Skip to content

Instantly share code, notes, and snippets.

@amalgjose
Created March 7, 2020 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amalgjose/3f6b58c36fa9602ec691adfa10745b3e to your computer and use it in GitHub Desktop.
Save amalgjose/3f6b58c36fa9602ec691adfa10745b3e to your computer and use it in GitHub Desktop.
Stack implementation using collections module in python
from collections import deque as dq
sample_stack = dq()
# Push elements to stack using append() function
# This is similar to the way we push elements to list
sample_stack.append('Sabitha')
sample_stack.append('Edward')
# Print all the elements in the stack
print('All the elements in the stack')
print(sample_stack)
# Retrieve the elements in LIFO order
print('\nRetrieve the elements from stack:')
print(sample_stack.pop())
print(sample_stack.pop())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment