Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- words = [word for word in input().split(" ")]
- command = input()
- while command != "3:1":
- if "merge" in command:
- action, startIndex, endIndex = command.split(" ")
- startIndex = int(startIndex)
- endIndex = int(endIndex)
- if startIndex < 0:
- words[:endIndex + 1] = [''.join(words[:endIndex + 1])]
- elif endIndex > len(words):
- words[startIndex:] = [''.join(words[startIndex:])]
- else:
- words[startIndex:endIndex+1] = [''.join(words[startIndex:endIndex+1])]
- elif "divide" in command:
- action, index, partitions = command.split(" ")
- index = int(index)
- partitions = int(partitions)
- word = list(words[index])
- words.pop(index)
- length = int(len(word))
- for i in range(partitions):
- if i == partitions - 1:
- words.insert(index + i, "".join(word[:]))
- else:
- words.insert(index+i, "".join(word[:int(length/partitions)]))
- word = word[int(length/partitions):]
- command = input()
- print(" ".join(words))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement