How do I implement a function that undoes the last input that modified a list? So I recently made a program that adds, removes (either just plain removes or by a user input [i.e. if an item is less than a user input then it gets deleted and the such]) and modifies packages (dictionaries containing beginning and end dates, destination and price) in a list (I already asked for help here once) When I implemented the remove/modify functions, I also made sure to append the original item to a new list so that when I had to call the undo function it'd just append the original item to the original list again, however, the function just deletes the item that was in the list after the remove/modify calls and just appends the item that got removed/modified What I tried to do (my train of thought) was that I wanted to create a new list called "lst" where I stock the items that were about to be removed, and I would essentially use it in the undo function (basically the function that you call undo list). In the undo function I enumerate thru l and lst, and I tried to append the item from the lst list. Now I see how I messed up given that the index will probably not be the same and I caught an IndexError so I resorted to popping the previous item
def undo(l,lst): for el,pachet in enumerate(l): l.append(lst[el]) l.pop()
the code: https://pastebin.com/taZAjhQf
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)