ramsess90

9 zad

Jan 27th, 2019
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. string_list = list(input())
  2.  
  3.  
  4. def shift_right(lst):
  5.     try:
  6.         return [lst[-1]] + lst[:-1]
  7.     except IndexError:
  8.         return lst
  9.  
  10.  
  11. def shift_left(lst):
  12.     temp = lst[0]
  13.     for index in range(len(lst) - 1):
  14.         lst[index] = lst[index + 1]
  15.         lst[index + 1] = temp
  16.     return lst
  17.  
  18.  
  19. while True:
  20.     whole_command = input().split()
  21.     command = whole_command[0]
  22.     if command == 'end':
  23.         print(''.join(string_list))
  24.         break
  25.     if command == 'Delete':
  26.         for index in range(int(whole_command[2]), int(whole_command[1]) - 1, -1):
  27.             del string_list[index]
  28.     if command == 'Insert':
  29.         start_index = int(whole_command[1])
  30.         for c_index in range(0, len(whole_command[2])):
  31.             string_list.insert(start_index, whole_command[2][c_index])
  32.             start_index += 1
  33.     if command == 'Right':
  34.         for i in range(int(whole_command[1])):
  35.             string_list = shift_right(string_list)
  36.     if command == 'Left':
  37.         for i in range(int(whole_command[1])):
  38.             string_list = shift_left(string_list)
Advertisement
Add Comment
Please, Sign In to add comment