Advertisement
bl00dt3ars

Untitled

Aug 20th, 2021
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. command = input()
  2. my_dict = {}
  3.  
  4. while not command == "End":
  5.     command_info = command.split()
  6.     command_name = command_info[0]
  7.     hero_name = command_info[1]
  8.  
  9.     if command_name == "Enroll":
  10.         if hero_name not in my_dict:
  11.             my_dict[hero_name] = []
  12.         else:
  13.             print(f"{hero_name} is already enrolled.")
  14.     elif command_name == "Learn":
  15.         spell_name = command_info[2]
  16.         if hero_name in my_dict:
  17.             if spell_name in my_dict[hero_name]:
  18.                 print(f"{hero_name} has already learnt {spell_name}.")
  19.             else:
  20.                 my_dict[hero_name].append(spell_name)
  21.         else:
  22.             print(f"{hero_name} doesn't exist.")
  23.     elif command_name == "Unlearn":
  24.         spell_name = command_info[2]
  25.         if hero_name not in my_dict:
  26.             print(f"{hero_name} doesn't exist.")
  27.         else:
  28.             if spell_name not in my_dict[hero_name]:
  29.                 print(f"{hero_name} doesn't know {spell_name}.")
  30.             else:
  31.                 my_dict[hero_name].remove(spell_name)
  32.     command = input()
  33.  
  34. print(f'Heroes:')
  35. for k, v in sorted(my_dict.items(), key=lambda kvp: (-len(kvp[1]), kvp[1])):
  36.     print(f'== {k}: {", ".join(v)}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement