fork download
  1. RoomItems = "ab ba abab"
  2. DirtyRoom = "ababaabb"
  3.  
  4. RoomItems = sorted(RoomItems.split(" "), key=len)[::-1]
  5.  
  6. def Yarr(RoomItems, DirtyRoom):
  7. for Item in RoomItems:
  8. if all(char in DirtyRoom[0:len(Item)] for char in Item):
  9. print Item, DirtyRoom[0:len(Item)]
  10. RoomItems.remove(Item)
  11. DirtyRoom = DirtyRoom.replace(DirtyRoom[0:len(Item)],"")+DirtyRoom[0:len(Item)]
  12. Yarr(RoomItems, DirtyRoom)
  13.  
  14. Yarr(RoomItems, DirtyRoom)
Success #stdin #stdout 0.01s 7896KB
stdin
Standard input is empty
stdout
abab abab