Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/python3.7
- # -*- coding: utf-8 -*import
- dwarfs = {}
- while True:
- data = input()
- if data == 'Once upon a time':
- break
- # data = data.split(' <:> ')
- # name = data[0]
- # hat_color = data[1]
- # physics = int(data[2])
- (name, hat_color, physics) = data.split(' <:> ')
- if hat_color not in dwarfs:
- dwarfs[hat_color] = {name: physics}
- else:
- if name not in dwarfs[hat_color]:
- dwarfs[hat_color].update({name: physics})
- else:
- if physics > dwarfs[hat_color][name]:
- dwarfs[hat_color][name] = physics
- extract_info = [(color, person, dwarfs[color][person],
- len(people)) for color, people in dwarfs.items() for person in people]
- order = sorted(extract_info, key=lambda x: (int(x[2]), x[3]), reverse=True)
- for i in order:
- print(f'({i[0]}) {i[1]} <-> {i[2]}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement