https://github.com/chenpi11/pystack
Python stack type implementation.
https://github.com/chenpi11/pystack
Last synced: 9 months ago
JSON representation
Python stack type implementation.
- Host: GitHub
- URL: https://github.com/chenpi11/pystack
- Owner: ChenPi11
- License: unlicense
- Created: 2024-04-14T06:23:01.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-14T06:47:43.000Z (over 1 year ago)
- Last Synced: 2025-02-14T23:32:34.313Z (11 months ago)
- Language: Python
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PyStack
A simple stack implementation in Python.
## Quick start
```python
stack = Stack() # Create an empty stack.
print(f"This is an empty stack: {repr(stack)}")
stack.push(1) # Push an item to the stack.
stack.push(2)
stack.push("STR")
print(f"This is a stack with 3 items: {repr(stack)}") # Show the stack.
print(f"Pop the top item: {repr(stack.pop())}") # Pop the top item.
print(f"This is a stack with 2 items: {repr(stack)}")
print(f"Pop all items: {repr(stack.pop_all())}") # Pop all items.
print(f"This is an empty stack: {repr(stack)}")
stack.push_all([4, 5, 6]) # Push all items.
print(f"Now the stack has 3 items: {repr(stack)}")
print(f"The size of the stack is {len(stack)}") # Get the length of the stack.
del stack[0] # Delete the first item.
print(f"Delete the first item: {repr(stack)}")
stack_copy = stack.copy() # Copy the stack.
print(
f"This is the copy of the stack: {repr(stack_copy)}, {id(stack)} => {id(stack_copy)}"
)
print(f"{stack_copy} == {stack}: {stack_copy == stack}")
```