Simple Text Editor

  • + 0 comments

    My python solution

    if name == 'main': text = [] edition = [] for _ in range(int(input())): op = input().split() if op[0] == '1': text.extend(op[1]) edition.append(len(op[1])) elif op[0] == '2': edition.append([]) for _ in range(int(op[1])): edition[-1].append(text.pop()) elif op[0] == '3': print(text[int(op[1])-1]) elif op[0] == '4': undo = edition.pop() if isinstance(undo, int): for _ in range(undo): text.pop() else: text.extend(undo[::-1])