Advertisement
koteshkoeziche

03. The Final Quest

Nov 6th, 2020
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. words = input().split()
  2.  
  3.  
  4. def delete_word(index):
  5. if index + 1 in range(len(words)):
  6. words.remove(words[index + 1])
  7. return words
  8.  
  9.  
  10. def swap_word(word_1, word_2):
  11. if word_1 in words and word_2 in words:
  12. index1 = words.index(word_1)
  13. index2 = words.index(word_2)
  14. words[index1], words[index2] = words[index2], words[index1]
  15. return words
  16.  
  17.  
  18. def put_word(word, index):
  19. if 0 <= index - 1 <= len(words):
  20. words.insert(index - 1, word)
  21. return words
  22.  
  23.  
  24. def sort_word(word1, word2):
  25. return words.reverse()
  26.  
  27.  
  28. def replace_word(word1, word2):
  29. if word2 in words:
  30. i = words.index(word2)
  31. words[i] = word1
  32. return words
  33.  
  34.  
  35. command = input()
  36.  
  37. while not command == "Stop":
  38. action = command.split()[0]
  39.  
  40.  
  41. if action == "Delete":
  42. index = int(command.split()[1])
  43. delete_word(int(index))
  44.  
  45. elif action == "Swap":
  46. word_1 = command.split()[1]
  47. word_2 = command.split()[2]
  48. swap_word(word_1, word_2)
  49.  
  50. elif action == "Put":
  51. word_1 = command.split()[1]
  52. index = int(command.split()[2])
  53. put_word(word_1, int(index))
  54.  
  55. elif action == "Sort":
  56. sort_word()
  57.  
  58. elif action == "Replace":
  59. word_1 = command.split()[1]
  60. word_2 = command.split()[2]
  61. replace_word(word_1, word_2)
  62.  
  63. command = input()
  64.  
  65. print(' '.join(words))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement