Undo and redo

actions is a list of strings: "undo" cancels the most recent action in effect, "redo" restores the most recently undone action, and anything else is a new action. A new action clears the redo history. Write final(actions) that returns the actions in effect, in order. Undo or redo with nothing to act on is ignored.

final(["a", "b", "undo", "redo"])        ->  ["a", "b"]
final(["a", "b", "undo", "c", "redo"])   ->  ["a", "c"]
final(["undo", "redo", "a"])             ->  ["a"]
def final(actions):
    ...