viligen

the_pianist

Nov 25th, 2021
393
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. n = int(input())
  2.  
  3. pieces = {}
  4.  
  5. for _ in range(n):
  6.     data = input().split("|")
  7.     piece, composer, key = data
  8.     pieces[piece] = [composer, key]
  9.  
  10. while True:
  11.     command = input().split("|")
  12.     if command[0] == "Stop":
  13.         break
  14.     elif command[0] == "Add":
  15.         piece, composer, key = command[1:]
  16.         if piece in pieces :
  17.             print(f"{piece} is already in the collection!")
  18.         else:
  19.             pieces[piece] = [composer, key]
  20.             print(f"{piece} by {composer} in {key} added to the collection!")
  21.     elif command[0] == "Remove":
  22.         piece = command[1]
  23.         if piece in pieces:
  24.             print(f"Successfully removed {piece}!")
  25.             del pieces[piece]
  26.         else:
  27.             print(f"Invalid operation! {piece} does not exist in the collection.")
  28.     elif command[0] == "ChangeKey":
  29.         piece, new_key = command[1:]
  30.         if piece in pieces:
  31.             pieces[piece][1] = new_key
  32.             print(f"Changed the key of {piece} to {new_key}!")
  33.         else:
  34.             print(f"Invalid operation! {piece} does not exist in the collection.")
  35.  
  36. sorted_pieces = sorted(pieces.items(), key=lambda kvp: (kvp[0], kvp[1][0]))
  37.  
  38. for piece_, composer_key in sorted_pieces:
  39.     print(f"{piece_} -> Composer: {composer_key[0]}, Key: {composer_key[1]}")
  40.  
  41.  
RAW Paste Data