Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def is_index_valid(some_index, some_list):
- if 0 <= some_index < len(some_list):
- return True
- print('Invalid index')
- def is_count_valid(some_count, some_list):
- if 0 < some_count <= len(some_list):
- return True
- print('Invalid count')
- data = list(map(int, input().split(' ')))
- command = input()
- while not command == 'end':
- command = command.split()
- if command[0] == 'exchange':
- index = int(command[1])
- if is_index_valid(index, data):
- left_side = data[:index + 1]
- right_side = data[index + 1:]
- data.clear()
- data = right_side + left_side
- elif command[0] == 'max':
- if command[1] == 'even':
- biggest_num = []
- for index in range(len(data)):
- if data[index] % 2 == 0:
- biggest_num.append(data[index])
- if len(biggest_num) == 0:
- print('No matches')
- else:
- biggest_num = max(biggest_num)
- searched_index = 0
- for rightmost in range(len(data) - 1, -1, -1):
- if data[rightmost] == biggest_num:
- print(rightmost)
- break
- elif command[1] == 'odd':
- biggest_num = []
- for index in range(len(data)):
- if data[index] % 2 != 0:
- biggest_num.append(data[index])
- if len(biggest_num) == 0:
- print('No matches')
- else:
- biggest_num = max(biggest_num)
- searched_index = 0
- for rightmost in range(len(data) - 1, -1, -1):
- if data[rightmost] == biggest_num:
- print(rightmost)
- break
- elif command[0] == 'min':
- if command[1] == 'even':
- min_num = []
- for index in range(len(data)):
- if data[index] % 2 == 0:
- min_num.append(data[index])
- if len(min_num) == 0:
- print('No matches')
- else:
- min_num = min(min_num)
- searched_index = 0
- for rightmost in range(len(data) - 1, -1, -1):
- if data[rightmost] == min_num:
- print(rightmost)
- break
- elif command[1] == 'odd':
- min_num = []
- for index in range(len(data)):
- if data[index] % 2 != 0:
- min_num.append(data[index])
- if len(min_num) == 0:
- print('No matches')
- else:
- min_num = min(min_num)
- searched_index = 0
- for rightmost in range(len(data) - 1, -1, -1):
- if data[rightmost] == min_num:
- print(rightmost)
- break
- elif command[0] == 'first':
- count = int(command[1])
- searched_nums = []
- if command[2] == 'even' and is_count_valid(count, data):
- for num in data:
- if num % 2 == 0:
- searched_nums.append(num)
- print(searched_nums[:count])
- elif command[2] == 'odd' and is_count_valid(count, data):
- for num in data:
- if num % 2 != 0:
- searched_nums.append(num)
- print(searched_nums[:count])
- elif command[0] == 'last':
- count = int(command[1])
- searched_nums = []
- if command[2] == 'even' and is_count_valid(count, data):
- for num in data:
- if num % 2 == 0:
- searched_nums.append(num)
- print(searched_nums[:count])
- elif command[2] == 'odd' and is_count_valid(count, data):
- for num in data:
- if num % 2 != 0:
- searched_nums.append(num)
- searched_nums = searched_nums[::-1]
- searched_nums = searched_nums[:count]
- print(searched_nums[::-1])
- command = input()
- print(data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement