deushiro

Untitled

Apr 1st, 2021 (edited)
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. people = {}
  2. with open('input1.txt') as f:
  3.     for line in f:
  4.         line = line.split(' ')
  5.         client = line[0]
  6.         product = line[1]
  7.         num = int(line[2])
  8.         if(client not in people):
  9.             people[client] = {}
  10.         if(product not in people[client]):
  11.             people[client][product] = num
  12.         else:
  13.             people[client][product] += num
  14.    
  15.  
  16. list_keys = list(people.keys())
  17. list_keys.sort()
  18. for i in list_keys:
  19.     print(i + ":")
  20.     list_ = list(people[i].keys())
  21.     list_.sort()
  22.     for j in list_:
  23.         print(j, people[i][j])
  24.  
  25.  
Add Comment
Please, Sign In to add comment