Advertisement
bl00dt3ars

3

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