Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. users_dict = {}
  2.  
  3. while True:
  4. command = input()
  5. if command == 'Statistics':
  6. break
  7. command = command.split('->')
  8. to_do = command[0]
  9. if to_do == 'Add':
  10. name = command[1]
  11. if name not in users_dict:
  12. users_dict[name] = []
  13. else:
  14. print(f'{name} is already registered')
  15. elif to_do == 'Send':
  16. name = command[1]
  17. mail = command[2]
  18. if name not in users_dict:
  19. users_dict[name] = []
  20. users_dict[name].append(mail)
  21. elif to_do == 'Delete':
  22. name = command[1]
  23. if name not in users_dict:
  24. print(f'{name} not found!')
  25. else:
  26. del users_dict[name]
  27.  
  28. users_dict_sort = dict(sorted(users_dict.items(), key=lambda x: (-len([1]), x[0])))
  29.  
  30. print(f'Users count: {len(users_dict_sort)}')
  31.  
  32. for k, v in users_dict_sort.items():
  33. print(k)
  34. for j in v:
  35. print(f' - {j}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement