Advertisement
bl00dt3ars

04. Snowwhite

Jun 26th, 2021
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. dwarfs = {}
  2. hats = {}
  3. command = input()
  4.  
  5. while not command == "Once upon a time":
  6.     name, color, physic = command.split(" <:> ")
  7.     physic = int(physic)
  8.     name = name + ":" + color
  9.     if name not in dwarfs:
  10.         if color not in hats:
  11.             hats[color] = 1
  12.         else:
  13.             hats[color] += 1
  14.         dwarfs[name] = (physic, color)
  15.     else:
  16.         if dwarfs[name][0] <= physic:
  17.             dwarfs[name] = (physic, color)
  18.     command = input()
  19.  
  20. for el in sorted(dwarfs.items(), key=lambda x: (x[1][0], hats[x[1][1]]), reverse=True):
  21.     name, color = el[0].split(":")
  22.     physic = el[1][0]
  23.     print(f"({color}) {name} <-> {physic}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement