python stack manager
Project description
PyStack
PyStack is a Python library for use stack. Stacks are a type of list-like variable but, with additional constraints (view more).
Installation
Use the package manager pip to install PyStack.
pip install pystack-manager
Use
Basic example
from pystack import Stack
stack = Stack() #create new stack
stack.push(5) #add element in stack
print(stack.pop()) #return and delete last element in stack
print(stack.last()) #return and don't delete last element in stack
Particular stack
Limited stack
The package allows to create a stack of fixed size.
from pystack import Stack
limited_stack = Stack(limite=5) #create new stack with fixed size
If we try to add more than the fixed size of the stack, an error is generated
Typed stack
The package allows to create a stack of stack with one element type.
from pystack import Stack
typed_stack = Stack(typed=int) #create stack accepting only integer
typed_stack_2 = Stack(typed=(int, float)) #create stack accepting only integer or float
If we try to add an element with a type not corresponding to the type of the stack, an error is generated.
In general
You can create stack with or without any of the previous options.
Stack modification
Add element
Several methods exist to add element to a stack.
Add one element:
stack.push(value) # add items to a stack
value can a stack, an object, an integer, a float or other.
Add items from one stack to another:
stack.transfer(another_stack) # add items from another_stack to a stack
another_stack can a stack, a list or a tuple.
Another solution:
stack = first_stack + second_stack #create new stack with elements of first_stack and second_stack
stack have same option (fixed size, typed) as first_stack
Get element
Two methods exist to get the last element of the stack.
value = stack.pop() #return and delete the last element of the stack
value = stack.last() #return and doesn't delete the last element of the stack
If stack is empty, an error is generated.
Comparison
Different technique can be applied to study a stack.
Equality:
if first_stack == second_stack:
#True statement
else:
#False statement
If first_stack elements are identical to those of the second, equality is respected (options are not necessarily the same).
Contains:
if value in stack: # True if value in the stack
#True statement
else:
#False statement
Other modifications
Reverse the stack:
s = Stack()
s.transfer([5, 8, 9])
print(s) # [5, 8, 9]
s.reverse()
print(s) # [9, 8, 5]
Split the stack:
s = Stack()
s.transfer([8, 6, 7, 2])
a = s.split(2)
print(s, a) # [8, 6] [7, 2]
Support
if you encounter any bugs, you can report them by email, by attaching the error message and the program.
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
Source Code
The code source can be found here
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pystack-manager-0.9.4.tar.gz.
File metadata
- Download URL: pystack-manager-0.9.4.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a5649d90723f91eb629e5922b6d67e4f9ba3581d5c74e05d48729c488731c84
|
|
| MD5 |
7dbdf8719a16ecb1f809ce35687d9566
|
|
| BLAKE2b-256 |
6b4f1a56218f3ef3fff1a657d478f5889a1242242b4c6987089beecffea324b3
|
File details
Details for the file pystack_manager-0.9.4-py2.py3-none-any.whl.
File metadata
- Download URL: pystack_manager-0.9.4-py2.py3-none-any.whl
- Upload date:
- Size: 17.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c6ac92d5623e8715bee40e92deaae355432f83b72b24ce7f8a1b985dfe4eedc
|
|
| MD5 |
15e28f8d3aa7de502e2a407d3b332821
|
|
| BLAKE2b-256 |
87b7d892c7677bd7930c3d5e97391176b7398cfb4b1be7f7c89bb9f63eb0875a
|