输入字符撤销恢复问题

1.撤销undo 恢复redo

if __name__ == '__main__':
    # undo undo redo wo ai ni undo zhen de undo undo kan redo yi undo
    data = input().split()
    if len(data) == 0:
        print("", end="")
    else:
        un_do = []
        result = []
        for idx,i in enumerate(data):
            if idx>0:
                print(result ,un_do,data[idx-1],len(result),len(un_do))
            if i == 'redo' and len(un_do) > 0:
                result.append(un_do.pop())
                continue
            elif i == 'undo' and len(result) > 0:
                un_do.append(result.pop())
                continue
            elif i!='redo' and i!='undo':
                result.append(i)
        print(" ".join(result), end="")
原文地址:https://www.cnblogs.com/sunupo/p/13514309.html