Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- command = input()
- my_dict = {}
- while not command == "End":
- command_info = command.split()
- command_name = command_info[0]
- hero_name = command_info[1]
- if command_name == "Enroll":
- if hero_name not in my_dict:
- my_dict[hero_name] = []
- else:
- print(f"{hero_name} is already enrolled.")
- elif command_name == "Learn":
- spell_name = command_info[2]
- if hero_name in my_dict:
- if spell_name in my_dict[hero_name]:
- print(f"{hero_name} has already learnt {spell_name}.")
- else:
- my_dict[hero_name].append(spell_name)
- else:
- print(f"{hero_name} doesn't exist.")
- elif command_name == "Unlearn":
- spell_name = command_info[2]
- if hero_name not in my_dict:
- print(f"{hero_name} doesn't exist.")
- else:
- if spell_name not in my_dict[hero_name]:
- print(f"{hero_name} doesn't know {spell_name}.")
- else:
- my_dict[hero_name].remove(spell_name)
- command = input()
- print(f'Heroes:')
- for k, v in sorted(my_dict.items(), key=lambda kvp: (-len(kvp[1]), kvp[1])):
- print(f'== {k}: {", ".join(v)}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement