Advertisement
simeonshopov

Snowwhite

Feb 7th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. #!/usr/local/bin/python3.7
  2. # -*- coding: utf-8 -*import
  3.  
  4. dwarfs = {}
  5.  
  6.  
  7. while True:
  8.     data = input()
  9.     if data == 'Once upon a time':
  10.         break
  11.     # data = data.split(' <:> ')
  12.     # name = data[0]
  13.     # hat_color = data[1]
  14.     # physics = int(data[2])
  15.     (name, hat_color, physics) = data.split(' <:> ')
  16.  
  17.     if hat_color not in dwarfs:
  18.         dwarfs[hat_color] = {name: physics}
  19.     else:
  20.         if name not in dwarfs[hat_color]:
  21.             dwarfs[hat_color].update({name: physics})
  22.         else:
  23.             if physics > dwarfs[hat_color][name]:
  24.                 dwarfs[hat_color][name] = physics
  25.  
  26. extract_info = [(color, person, dwarfs[color][person],
  27.                  len(people)) for color, people in dwarfs.items() for person in people]
  28.  
  29. order = sorted(extract_info, key=lambda x: (int(x[2]), x[3]), reverse=True)
  30.  
  31. for i in order:
  32.     print(f'({i[0]}) {i[1]} <-> {i[2]}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement