Advertisement
Guest User

DH

a guest
Nov 18th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. from typing import Dict
  2.  
  3. with open('input.txt') as input_file:
  4.     customers = dict()         # type: Dict[str, Dict[str, int]]
  5.     for line in input_file:
  6.         name, product, amount = line.split()
  7.         if name in customers and product in customers[name]:
  8.             customers[name][product] += int(amount)
  9.         elif name in customers:
  10.             customers[name][product] = int(amount)
  11.         else:
  12.             customers[name] = {product: int(amount)}
  13. for name in sorted(customers):
  14.     print(name, ":", sep="")
  15.     for product in sorted(customers[name]):
  16.         print(product, customers[name][product])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement