Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. my_dict = {}
  2. while True:
  3.     string = input()
  4.     if string == "Log out":
  5.         break
  6.     else:
  7.         token = string.split(": ")
  8.         command = token[0]
  9.         if command == "New follower":
  10.             username = token[1]
  11.             if username in my_dict:
  12.                 pass
  13.             else:
  14.                 my_dict[username] = 0
  15.         elif command == "Like":
  16.             username = token[1]
  17.             count = int(token[2])
  18.             if username not in my_dict:
  19.                 my_dict[username] = 0
  20.             my_dict[username] += count
  21.         elif command == "Comment":
  22.             username = token[1]
  23.             if username not in my_dict:
  24.                 my_dict[username] = 0
  25.             my_dict[username] += 1
  26.         elif command == "Blocked":
  27.             username = token[1]
  28.             if username not in my_dict:
  29.                 print(f"{username} doesn't exist.")
  30.             else:
  31.                  my_dict.pop(username)
  32.  
  33. print(f"{len(my_dict)} followers")
  34. for key, value in sorted(my_dict.items(), key= lambda x: (-x[1], x[0])):
  35.     print(f"{key}: {value}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement