Created
March 7, 2020 06:13
-
-
Save amalgjose/3f6b58c36fa9602ec691adfa10745b3e to your computer and use it in GitHub Desktop.
Stack implementation using collections module in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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