Advertisement
Kamend1

Kamen_Dimitrov_list_manipulator

Sep 29th, 2023
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. numbers = list(int(x) for x in input().split(" "))
  2. even = []
  3. odd = []
  4. new_list = []
  5.  
  6. for element in numbers:
  7. if element % 2 == 0:
  8. even.append(element)
  9. else:
  10. odd.append(element)
  11.  
  12. while True:
  13. user_command = input()
  14. if user_command[:8] == "exchange":
  15. idx = int(user_command[9:])
  16. if idx < 0 or idx >= len(numbers):
  17. print("Invalid index")
  18. continue
  19. numbers_1 = numbers[:idx + 1]
  20. numbers_2 = numbers[idx + 1:]
  21. numbers = numbers_2 + numbers_1
  22. elif user_command == "max odd":
  23. if not odd:
  24. print("No matches")
  25. continue
  26. max_odd = max(odd)
  27. for i in range(len(numbers) - 1, - 1, - 1):
  28. if numbers[i] == max_odd:
  29. print(i)
  30. break
  31. elif user_command == "max even":
  32. if not even:
  33. print("No matches")
  34. continue
  35. max_even = max(even)
  36. for i in range(len(numbers) - 1, - 1, - 1):
  37. if max_even == numbers[i]:
  38. print(i)
  39. break
  40. elif user_command == "min even":
  41. if not even:
  42. print("No matches")
  43. continue
  44. min_even = min(even)
  45. for i in range(len(numbers) - 1, - 1, - 1):
  46. if numbers[i] == min_even:
  47. print(i)
  48. break
  49. elif user_command == "min odd":
  50. if not odd:
  51. print("No matches")
  52. continue
  53. min_odd = min(odd)
  54. for i in range(len(numbers) - 1, - 1, - 1):
  55. if numbers[i] == min_odd:
  56. print(i)
  57. break
  58. elif user_command[:5] == "first":
  59. new_list = []
  60. if user_command[8:] == "even":
  61. counter = int(user_command[6])
  62. if counter > len(numbers):
  63. print("Invalid count")
  64. continue
  65. for num in numbers:
  66. if num % 2 == 0:
  67. new_list.append(num)
  68. if counter == len(new_list):
  69. break
  70. elif user_command[8:] == "odd":
  71. counter = int(user_command[6])
  72. if counter > len(numbers):
  73. print("Invalid count")
  74. continue
  75. for num in numbers:
  76. if num % 2 != 0:
  77. new_list.append(num)
  78. if counter == len(new_list):
  79. break
  80. print(new_list)
  81. elif user_command[:4] == "last":
  82. new_list = []
  83. if user_command[7:] == "even":
  84. counter = int(user_command[5])
  85. if counter > len(numbers):
  86. print("Invalid count")
  87. continue
  88. for idx in range(len(numbers) - 1, -1, -1):
  89. if numbers[idx] % 2 == 0:
  90. new_list.insert(0, numbers[idx])
  91. if counter == len(new_list):
  92. break
  93. elif user_command[7:] == "odd":
  94. counter = int(user_command[5])
  95. if counter > len(numbers):
  96. print("Invalid count")
  97. continue
  98. for idx in range(len(numbers) - 1, -1, -1):
  99. if numbers[idx] % 2 != 0:
  100. new_list.insert(0, numbers[idx])
  101. if counter == len(new_list):
  102. break
  103. print(new_list)
  104. elif user_command == "end":
  105. print(numbers)
  106. break
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement