Advertisement
KNenov96

list manipulator

Oct 5th, 2022
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.94 KB | None | 0 0
  1. numbers_for_manipulating = list(map(int, input().split()))
  2. command = input()
  3.  
  4.  
  5. while command != "end":
  6.     current_command = command.split()[0]
  7.     if current_command == "exchange":
  8.         split_index = int(command.split()[1])
  9.         if split_index >= len(numbers_for_manipulating) or split_index < 0:
  10.             print("Invalid index")
  11.         else:
  12.             numbers_for_manipulating = numbers_for_manipulating[split_index+1:] + numbers_for_manipulating[:split_index+1]
  13.     elif current_command == "max":
  14.         odd_or_even = command.split()[1]
  15.         max_num = "No matches"
  16.         if odd_or_even == "odd":
  17.             if odd_or_even == "odd":
  18.                 if [x for x in numbers_for_manipulating if x % 2 != 0]:
  19.                     for index, data in enumerate(numbers_for_manipulating):
  20.                         if data == max([x for x in numbers_for_manipulating if x % 2 != 0]):
  21.                             max_num = index
  22.         elif odd_or_even == "even":
  23.             if [x for x in numbers_for_manipulating if x % 2 == 0]:
  24.                 for index, data in enumerate(numbers_for_manipulating):
  25.                     if data == max([x for x in numbers_for_manipulating if x % 2 == 0]):
  26.                         max_num = index
  27.         print(max_num)
  28.     elif current_command == "min":
  29.         odd_or_even = command.split()[1]
  30.         min_num = "No matches"
  31.         if odd_or_even == "odd":
  32.             if [x for x in numbers_for_manipulating if x % 2 != 0]:
  33.                 for index, data in enumerate(numbers_for_manipulating):
  34.                     if data == min([x for x in numbers_for_manipulating if x % 2 != 0]):
  35.                         min_num = index
  36.         elif odd_or_even == "even":
  37.             if [x for x in numbers_for_manipulating if x % 2 == 0]:
  38.                 for index, data in enumerate(numbers_for_manipulating):
  39.                     if data == min([x for x in numbers_for_manipulating if x % 2 == 0]):
  40.                         min_num = index
  41.         print(min_num)
  42.     elif current_command == "first" or current_command == "last":
  43.         count = int(command.split()[1])
  44.         if count <= len(numbers_for_manipulating):
  45.             if command.split()[2] == "even" and current_command == "first":
  46.                 print([x for x in numbers_for_manipulating if x % 2 == 0][:count])
  47.             elif command.split()[2] == "odd" and current_command == "first":
  48.                 print([x for x in numbers_for_manipulating if x % 2 != 0][:count])
  49.             elif command.split()[2] == "even" and current_command == "last":
  50.                 print(list(reversed([x for x in reversed(numbers_for_manipulating) if x % 2 == 0][:count])))
  51.             elif command.split()[2] == "odd" and current_command == "last":
  52.                 print(list(reversed([x for x in reversed(numbers_for_manipulating) if x % 2 != 0][:count])))
  53.         else:
  54.             print("Invalid count")
  55.  
  56.     command = input()
  57. print(numbers_for_manipulating)
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement