Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- line_numbers = input().split()
- command_info = input()
- my_integers_list = []
- for item in line_numbers:
- if item.isdigit():
- integer_numbers = int(item)
- my_integers_list.append(integer_numbers)
- while command_info != "end":
- sub_list_first = []
- sub_list_second = []
- command = command_info.split()[0]
- if command == "exchange":
- index = command_info.split()[1]
- index = int(index)
- if index not in range(len(my_integers_list)):
- print("Invalid index")
- else:
- for item in range(len(my_integers_list)):
- if item > index:
- sub_list_second.append(my_integers_list[item])
- else:
- sub_list_first.append(my_integers_list[item])
- sub_list_second.extend(sub_list_first)
- my_integers_list = sub_list_second
- elif command == "max":
- kind_number = command_info.split()[1]
- if kind_number == "even":
- even_numbers = [num for num in my_integers_list if num % 2 == 0]
- if not even_numbers:
- print("No matches")
- else:
- max_even = max(even_numbers)
- max_even_index = len(my_integers_list) - my_integers_list[::-1].index(max_even) - 1
- print(max_even_index)
- elif kind_number == "odd":
- odd_numbers = [num for num in my_integers_list if num % 2 != 0]
- if not odd_numbers:
- print("No matches")
- else:
- max_odd = max(odd_numbers)
- max_odd_index = len(my_integers_list) - my_integers_list[::-1].index(max_odd) - 1
- print(max_odd_index)
- elif command == "min":
- kind_number = command_info.split()[1]
- if kind_number == "even":
- even_numbers = [num for num in my_integers_list if num % 2 == 0]
- if not even_numbers:
- print("No matches")
- else:
- min_even = min(even_numbers)
- min_even_index = len(my_integers_list) - my_integers_list[::-1].index(min_even) - 1
- print(min_even_index)
- elif kind_number == "odd":
- odd_numbers = [num for num in my_integers_list if num % 2 != 0]
- if not odd_numbers:
- print("No matches")
- else:
- min_odd = min(odd_numbers)
- min_odd_index = len(my_integers_list) - my_integers_list[::-1].index(min_odd) - 1
- print(min_odd_index)
- elif command == "first":
- count = command_info.split()[1]
- count = int(count)
- kind_number = command_info.split()[2]
- if kind_number == "even":
- even_numbers = [num for num in my_integers_list if num % 2 == 0]
- if count > len(my_integers_list):
- print("Invalid count")
- elif not even_numbers:
- print("[]")
- else:
- count = min(count, len(even_numbers))
- first_elements = [even_numbers[i] for i in range(count)]
- print(first_elements)
- elif kind_number == "odd":
- odd_numbers = [num for num in my_integers_list if num % 2 != 0]
- if count > len(my_integers_list):
- print("Invalid count")
- elif not odd_numbers:
- print("[]")
- else:
- count = min(count, len(odd_numbers))
- first_elements = [odd_numbers[i] for i in range(count)]
- print(first_elements)
- elif command == "last":
- count = command_info.split()[1]
- count = int(count)
- kind_number = command_info.split()[2]
- if kind_number == "even":
- even_numbers = [num for num in my_integers_list if num % 2 == 0]
- if count > len(my_integers_list):
- print("Invalid count")
- elif not even_numbers:
- print("[]")
- else:
- count = min(count, len(even_numbers))
- first_elements = [even_numbers[i] for i in range(len(even_numbers) - count, len(even_numbers))]
- print(first_elements)
- elif kind_number == "odd":
- odd_numbers = [num for num in my_integers_list if num % 2 != 0]
- if count > len(my_integers_list):
- print("Invalid count")
- elif not odd_numbers:
- print("[]")
- else:
- count = min(count, len(odd_numbers))
- first_elements = [odd_numbers[i] for i in range(len(odd_numbers) - count, len(odd_numbers))]
- print(first_elements)
- command_info = input()
- print(my_integers_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement