Advertisement
ivominchev

On the Way to Annapurna

Jul 14th, 2020
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. stores = {}
  2.  
  3. while True:
  4. tokens = input().split('->')
  5. if tokens[0] == "END":
  6. break
  7. else:
  8. command = tokens[0]
  9. store = tokens[1]
  10.  
  11. if command == "Add":
  12.  
  13. store_items = tokens[2].split(',')
  14.  
  15. if store not in stores:
  16. stores[store] = []
  17.  
  18. for item in store_items:
  19. stores[store].append(item)
  20.  
  21. elif command == "Remove":
  22. if store in stores:
  23. del stores[store]
  24.  
  25. stores_sorted = sorted(stores.items(), key=lambda a: (len(a[1]), a), 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