Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. def swap_position(list, pos1, pos2):
  2. list[pos1], list[pos2] = list[pos2], list[pos1]
  3. return list
  4.  
  5.  
  6. paintings = input().split(' ')
  7.  
  8. command = input()
  9.  
  10. while command != "END":
  11. tokens = command.split(' ')
  12. if tokens[0] == "Change":
  13. painting_number = tokens[1]
  14. changed_number = tokens[2]
  15. for i in range(len(paintings)):
  16. if paintings[i] == painting_number:
  17. paintings[i] = changed_number
  18. break
  19.  
  20. elif tokens[0] == 'Hide':
  21. painting_number = tokens[1]
  22. if painting_number in paintings:
  23. paintings.remove(painting_number)
  24.  
  25. elif tokens[0] == 'Switch':
  26. painting_number = tokens[1]
  27. changed_number = tokens[2]
  28. if painting_number in paintings and changed_number in paintings:
  29. a, b = paintings.index(painting_number), paintings.index(changed_number)
  30. swap_position(paintings, a, b)
  31.  
  32. elif tokens[0] == 'Insert':
  33. idx = int(tokens[1])
  34. painting_number = tokens[2]
  35. if 0 <= idx <= len(paintings):
  36. paintings.insert(idx + 1, painting_number)
  37.  
  38. elif tokens[0] == 'Reverse':
  39. paintings = paintings[::-1]
  40. command = input()
  41.  
  42.  
  43. print(' '.join(paintings))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement