SHARE
TWEET

Array Manipulatopr

SimeonTs Aug 15th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys
  2. the_list = [int(item) for item in input().split()]
  3.  
  4. while True:
  5.     command = input().split()
  6.     if command[0] == "end":
  7.         break
  8.  
  9.     elif command[0] == "exchange":
  10.         index_to_exchange = int(command[1])
  11.         if len(the_list) > index_to_exchange >= 0:
  12.             the_list = the_list[index_to_exchange + 1:] + the_list[:index_to_exchange + 1]
  13.         else:
  14.             print("Invalid index")
  15.  
  16.     elif command[0] == "max":
  17.         max_number = -sys.maxsize - 1
  18.         index_of_number = -1
  19.         if command[1] == "even":
  20.             for number in range(len(the_list)):
  21.                 if the_list[number] % 2 == 0 and the_list[number] >= max_number:
  22.                     max_number = the_list[number]
  23.                     index_of_number = number
  24.         elif command[1] == "odd":
  25.             for number in range(len(the_list)):
  26.                 if the_list[number] % 2 != 0 and the_list[number] >= max_number:
  27.                     max_number = the_list[number]
  28.                     index_of_number = number
  29.         if index_of_number == -1:
  30.             print("no matches")
  31.         else:
  32.             print(index_of_number)
  33.  
  34.     elif command[0] == "min":
  35.         min_number = sys.maxsize
  36.         index_of_number = -1
  37.         if command[1] == "even":
  38.             for number in range(len(the_list)):
  39.                 if the_list[number] % 2 == 0 and the_list[number] <= min_number:
  40.                     min_number = the_list[number]
  41.                     index_of_number = number
  42.         elif command[1] == "odd":
  43.             for number in range(len(the_list)):
  44.                 if the_list[number] % 2 != 0 and the_list[number] <= min_number:
  45.                     min_number = the_list[number]
  46.                     index_of_number = number
  47.         if index_of_number == -1:
  48.             print("No matches")
  49.         else:
  50.             print(index_of_number)
  51.  
  52.     elif command[0] == "first":
  53.         count_numbers = int(command[1])
  54.         if count_numbers > len(the_list):
  55.             print("Invalid count")
  56.             continue
  57.         if command[2] == "even":
  58.             print([item for item in the_list if item % 2 == 0][:count_numbers])
  59.         elif command[2] == "odd":
  60.             print([item for item in the_list if item % 2 != 0][:count_numbers])
  61.  
  62.     elif command[0] == "last":
  63.         count_numbers = int(command[1])
  64.         if count_numbers > len(the_list):
  65.             print("Invalid count")
  66.             continue
  67.         if command[2] == "even":
  68.             print([item for item in the_list if item % 2 == 0][-count_numbers:])
  69.         elif command[2] == "odd":
  70.             print([item for item in the_list if item % 2 != 0][-count_numbers:])
  71.  
  72. print(the_list)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top