Advertisement
Guest User

Untitled

a guest
Mar 24th, 2020
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. dd = {}
  2. unliked = 0
  3.  
  4. while True :
  5. what = input().split("-")
  6. line_one = what[0]
  7. if "Stop" == line_one:
  8. break
  9. who = what[1]
  10. meal = what[2]
  11.  
  12.  
  13. if line_one == "Like":
  14. if who in dd and meal not in dd[who]:
  15. dd[who].append(meal)
  16. else :
  17. dd[who] = []
  18. if meal != "":
  19. dd[who].append(meal)
  20. elif line_one == "Unlike":
  21. if who not in dd:
  22. print(f"{who} is not at the party.")
  23. else :
  24. if meal not in dd[who]:
  25.  
  26. print(f"{who} doesn't have the {meal} in his/her collection.")
  27. else :
  28. for v in dd[who]:
  29. if v.lower() == meal.lower():
  30. dd[who].remove(meal)
  31. unliked += 1
  32. break
  33. print(f"{who} doesn't like the {meal}.")
  34.  
  35. sortem = dict(sorted(dd.items(), key=lambda x: (-len(x[1]), x[0])))
  36.  
  37. for k,v in sortem.items():
  38.  
  39. print(f"{k}: {', '.join(v)}")
  40. print(f"Unliked meals: {unliked}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement