yordan_yordanov

P3

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