Advertisement
snow27

The Pianist

Dec 3rd, 2020
1,462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1.  
  2. n = int(input())
  3.  
  4. collection = {}
  5.  
  6. for i in range(n):
  7.     text_input = input().split('|')
  8.     p = text_input[0]
  9.     com = text_input[1]
  10.     k = text_input[2]
  11.     collection[p] = [com, k]
  12.  
  13. command = input()
  14.  
  15. while not command == "Stop":
  16.     command = command.split('|')
  17.     type_command = command[0]
  18.     piece = command[1]
  19.     if type_command == 'Add':
  20.         composer = command[2]
  21.         key = command[3]
  22.         if piece in collection:
  23.             print(f"{piece} is already in the collection!")
  24.         else:
  25.             collection[piece] = [composer, key]
  26.             print(f"{piece} by {composer} in {key} added to the collection!")
  27.     elif type_command == 'Remove':
  28.         if piece in collection:
  29.             del collection[piece]
  30.             print(f"Successfully removed {piece}!")
  31.         else:
  32.             print(f"Invalid operation! {piece} does not exist in the collection.")
  33.     elif type_command == 'ChangeKey':
  34.         new_key = command[2]
  35.         if piece in collection:
  36.             collection[piece][1] = new_key
  37.             print(f"Changed the key of {piece} to {new_key}!")
  38.         else:
  39.             print(f"Invalid operation! {piece} does not exist in the.")
  40.     command = input()
  41.  
  42. collection = dict(sorted(collection.items(), key=lambda x: (x[0],x[1][0])))
  43.  
  44.  
  45. for piece in collection:
  46.     print(f"{piece} -> Composer: {collection[piece][0]}, Key: {collection[piece][1]}")
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement