GeorgiLukanov87

anonymous_treat_not_mine

Jun 7th, 2022 (edited)
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. # Not my code. this exercise sux !
  2.  
  3. from math import floor
  4. given_string = input()
  5. given_list = given_string.split(" ")
  6.  
  7. while True:
  8.     command = input()
  9.     if command == "3:1":
  10.         print(" ".join(given_list[0:]))
  11.         break
  12.     command_list = command.split(" ")
  13.     if command_list[0] == "merge":
  14.         start_index = int(command_list[1])
  15.         end_index = int(command_list[2])
  16.         if start_index < 0:
  17.             start_index = 0
  18.         if end_index > (len(given_list) - 1):
  19.             end_index = len(given_list)- 1
  20.         merged_string = "".join(given_list[start_index:(end_index + 1)])
  21.         given_list[start_index:end_index + 1] = [merged_string]
  22.     if command_list[0] == "divide":
  23.         index = int(command_list[1])
  24.         partitions = int(command_list[2])
  25.         chosen_elem = given_list[index]
  26.         partition_length = floor(len(chosen_elem)/partitions)
  27.         partitioned_list = []
  28.         for i in range(0, partitions):
  29.             if i != (partitions - 1):
  30.                 partitioned_list.append(chosen_elem[i*partition_length:(i+1)*partition_length:])
  31.             else:
  32.                 partitioned_list.append(chosen_elem[i * partition_length:])
  33.         given_list[index:index+1] = partitioned_list
Add Comment
Please, Sign In to add comment