pystack-manager 0.9.4

Creator: railscoder56

Last updated:

Add to Cart

Description:

pystackmanager 0.9.4

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
GNU GPLv3

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.