Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2025
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | Source Code | 0 0
  1. words = [word for word in input().split(" ")]
  2. command = input()
  3. while command != "3:1":
  4.     if "merge" in command:
  5.         action, startIndex, endIndex = command.split(" ")
  6.         startIndex = int(startIndex)
  7.         endIndex = int(endIndex)
  8.         if startIndex < 0:
  9.             words[:endIndex + 1] = [''.join(words[:endIndex + 1])]
  10.         elif endIndex > len(words):
  11.             words[startIndex:] = [''.join(words[startIndex:])]
  12.         else:
  13.             words[startIndex:endIndex+1] = [''.join(words[startIndex:endIndex+1])]
  14.     elif "divide" in command:
  15.         action, index, partitions = command.split(" ")
  16.         index = int(index)
  17.         partitions = int(partitions)
  18.         word = list(words[index])
  19.         words.pop(index)
  20.         length = int(len(word))
  21.         for i in range(partitions):
  22.             if i == partitions - 1:
  23.                 words.insert(index + i, "".join(word[:]))
  24.             else:
  25.                 words.insert(index+i, "".join(word[:int(length/partitions)]))
  26.             word = word[int(length/partitions):]
  27.  
  28.     command = input()
  29. print(" ".join(words))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement