I implemented basic pushd and popd functionality for a Python script. What's a more academic/formal way to implement a directory stack?
_directory_stack = {0:getcwd()}
def pushd(target: str):
"""Push a new directory to the top of the stack and changes to it.
Arguments:
target {str} -- Where you want to go
"""
highest_seen = max(_directory_stack.keys())
_directory_stack[highest_seen+1] = target
chdir(target)
def popd():
"""Pops the most recent directory off the stop of the stack and returns you to the previous directory
"""
current_top = max(_directory_stack.keys())
_directory_stack.pop(current_top, None)
chdir(_directory_stack[current_top-1])