kostovhg

srubsko unleashed

Aug 14th, 2021
1,103
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import re
  2.  
  3. pattern = re.compile(
  4.     r"^(?P<name>\w+(?: \w+)*) \@(?P<venue>\w+(?: \w+)*) (?P<price>\d+) (?P<count>\d+)$")
  5. venues = {}
  6.  
  7. while True:
  8.     line = input()
  9.     if line == 'End':
  10.         break
  11.     match_object = re.match(pattern, line)
  12.     if match_object:
  13.         venue = match_object.group('venue')
  14.         signer = match_object.group('name')
  15.         income = int(match_object.group('price')) * int(match_object.group('count'))
  16.         venues.setdefault(venue, {})
  17.         venues[venue].setdefault(signer, 0)
  18.         venues[venue][signer] += income
  19.  
  20. for v in venues:
  21.     print(v)
  22.     for s, i in sorted(venues[v].items(), key=lambda x: -x[1]):
  23.         print(f"#  {s} -> {i}")
RAW Paste Data