📅 2012-Apr-18 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ list, python, stack ⬩ 📚 Archive
The humble list
can be used as a stack in Python. Unlike using list as queue, using list as stack is optimal.
= []
stk
for i in range( 0, 5 ):
# Push to stack
stk.append( i )
while stk: # Stack not empty
= stk.pop() # Pop from stack
j print( j )
# Output: 4 3 2 1 0