jootiee

Untitled

Mar 2nd, 2022 (edited)
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. from sys import stdin
  2. import json
  3.  
  4.  
  5. data = [elem.split(", ") for elem in map(str.strip, stdin)]
  6.  
  7. result = dict()
  8.  
  9. for elem in data:
  10.     try:
  11.         try:
  12.             result[elem[0]][elem[2]].append(elem[1])
  13.         except Exception:
  14.             result[elem[0]][elem[2]] = [elem[1]]
  15.     except Exception:
  16.         result[elem[0]] = {elem[2]: [elem[1]]}
  17.  
  18. with open('kangaroo.json', 'w') as file:
  19.     for size in result:
  20.         for place in result[size]:
  21.             result[size][place].sort(reverse=True)
  22.     json.dump(result, file)
  23.  
Add Comment
Please, Sign In to add comment