Advertisement
DiYane

The Pianist /old

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