Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- pattern = re.compile(
- r"^(?P<name>\w+(?: \w+)*) \@(?P<venue>\w+(?: \w+)*) (?P<price>\d+) (?P<count>\d+)$")
- venues = {}
- while True:
- line = input()
- if line == 'End':
- break
- match_object = re.match(pattern, line)
- if match_object:
- venue = match_object.group('venue')
- signer = match_object.group('name')
- income = int(match_object.group('price')) * int(match_object.group('count'))
- venues.setdefault(venue, {})
- venues[venue].setdefault(signer, 0)
- venues[venue][signer] += income
- for v in venues:
- print(v)
- for s, i in sorted(venues[v].items(), key=lambda x: -x[1]):
- print(f"# {s} -> {i}")
Advertisement
Add Comment
Please, Sign In to add comment