Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. peopleMeals = {}
  2. unliked = 0
  3. line = input()
  4. while line != "Stop":
  5.     tokens = line.split("-")
  6.     if tokens[0] == "Like":
  7.         guest = tokens[1]
  8.         meal = tokens[2]
  9.         if guest not in peopleMeals:
  10.             peopleMeals[guest] = []
  11.         if meal not in peopleMeals[guest]:
  12.             peopleMeals[guest].append(meal)
  13.     if tokens[0] == "Unlike":
  14.         guest = tokens[1]
  15.         meal = tokens[2]
  16.         if guest not in peopleMeals:
  17.             print(f"{guest} is not at the party.")
  18.         elif meal not in peopleMeals[guest]:
  19.             print(f"{guest} doesn't have the {meal} in his/her collection.")
  20.         elif meal in peopleMeals[guest]:
  21.             unliked += 1
  22.             print(f"{guest} doesn't like the {meal}.")
  23.             peopleMeals[guest].remove(meal)
  24.     line = input()
  25. for k, v in sorted(peopleMeals.items(), key=lambda x: (-len(x[1]), x[0])):
  26.     print(f"{k}: {', '.join(v)}")
  27. print(f"Unliked meals: {unliked}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement