Advertisement
andonyan

On the way to Annapurna

Mar 8th, 2020
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. import re
  2.  
  3. stores = {}
  4.  
  5. while True:
  6.     tokens = re.split("->|,", input())
  7.     if tokens[0] == 'END':
  8.         break
  9.     else:
  10.         command = tokens[0]
  11.         store = tokens[1]
  12.         if command == 'Add':
  13.             if store not in stores:
  14.                 stores[store] = []
  15.                 for item in tokens[2:]:
  16.                     stores[store].append(item)
  17.             else:
  18.                 for item in tokens[2:]:
  19.                     stores[store].append(item)
  20.  
  21.         else:
  22.             if store in stores:
  23.                 del stores[store]
  24.  
  25. stores_sorted = sorted(stores.items(), key=lambda a: len(a[1]), reverse=True)
  26. print('Stores list:')
  27. for key, value in stores_sorted:
  28.     print(f'{key}')
  29.     for item in value:
  30.         print(f'<<{item}>>')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement