Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- list_numbers_ = input().split()
- list_numbers = list(map(int, list_numbers_))
- evens = []
- odds = []
- current_list = []
- while True:
- command = input()
- if command == "end":
- break
- command_split = command.split()
- if command_split[0] == "exchange" and 0 <= int(command_split[1]) < len(list_numbers):
- index = int(command_split[1])
- current_list = list_numbers[index+1:] + list_numbers[:index+1]
- list_numbers = current_list[:]
- elif command_split[0] == "exchange":
- print("Invalid index")
- elif command_split[0] == "max" and command_split[1] == "even":
- for i in range(len(list_numbers) - 1, -1, -1):
- if int(list_numbers[i]) % 2 == 0:
- evens.append(list_numbers[i])
- if len(evens) > 0:
- list_index = [i for i, number in enumerate(list_numbers) if number == max(evens)]
- index_even = max(list_index)
- print(index_even)
- evens = []
- else:
- print("No matches")
- elif command_split[0] == "max" and command_split[1] == "odd":
- for i in range(len(list_numbers) - 1, -1, -1):
- if int(list_numbers[i]) % 2 != 0:
- odds.append(list_numbers[i])
- if len(odds) > 0:
- list_index = [i for i, number in enumerate(list_numbers) if number == max(odds)]
- index_odds = max(list_index)
- print(index_odds)
- odds = []
- else:
- print("No matches")
- elif command_split[0] == "min" and command_split[1] == "even":
- for i in range(len(list_numbers) - 1, -1, -1):
- if int(list_numbers[i]) % 2 == 0:
- evens.append(list_numbers[i])
- if len(evens) > 0:
- list_index = [i for i, number in enumerate(list_numbers) if number == min(evens)]
- index_even = max(list_index)
- print(index_even)
- evens = []
- else:
- print("No matches")
- elif command_split[0] == "min" and command_split[1] == "odd":
- for i in range(len(list_numbers) - 1, -1, -1):
- if int(list_numbers[i]) % 2 != 0:
- odds.append(list_numbers[i])
- if len(odds) > 0:
- list_index = [i for i, number in enumerate(list_numbers) if number == min(odds)]
- index_odds = max(list_index)
- print(index_odds)
- odds = []
- else:
- print("No matches")
- elif command_split[0] == "first" and command_split[2] == "even":
- if int(command_split[1]) > len(list_numbers):
- print("Invalid count")
- else:
- for i in range(len(list_numbers)):
- if int(list_numbers[i]) % 2 == 0:
- evens.append(list_numbers[i])
- if len(evens) == int(command_split[1]):
- break
- print([int(digit) for digit in evens])
- evens = []
- elif command_split[0] == "first" and command_split[2] == "odd":
- if int(command_split[1]) > len(list_numbers):
- print("Invalid count")
- else:
- for i in range(len(list_numbers)):
- if int(list_numbers[i]) % 2 != 0:
- odds.append(list_numbers[i])
- if len(odds) == int(command_split[1]):
- break
- print([int(digit) for digit in odds])
- odds = []
- elif command_split[0] == "last" and command_split[2] == "even":
- if int(command_split[1]) > len(list_numbers):
- print("Invalid count")
- else:
- for i in range(len(list_numbers) - 1, -1, -1):
- if int(list_numbers[i]) % 2 == 0:
- evens.append(list_numbers[i])
- if len(evens) == int(command_split[1]):
- break
- print([int(digit) for digit in reversed(evens)])
- evens = []
- elif command_split[0] == "last" and command_split[2] == "odd":
- if int(command_split[1]) > len(list_numbers):
- print("Invalid count")
- else:
- for i in range(len(list_numbers)-1, -1, -1):
- if int(list_numbers[i]) % 2 != 0:
- odds.append(list_numbers[i])
- if len(odds) == int(command_split[1]):
- break
- print([int(digit) for digit in reversed(odds)])
- odds = []
- print([int(n) for n in list_numbers])
Add Comment
Please, Sign In to add comment