Skip to main content

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

GNU GPLv3

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pystack-manager-0.9.4a0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pystack_manager-0.9.4a0-py2.py3-none-any.whl (17.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pystack-manager-0.9.4a0.tar.gz.

File metadata

  • Download URL: pystack-manager-0.9.4a0.tar.gz
  • Upload date:
  • Size: 5.2 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

Hashes for pystack-manager-0.9.4a0.tar.gz
Algorithm Hash digest
SHA256 13586840765bb7e87fd229b3ebf57c1d3363256931543e11334059c2422da5c3
MD5 37f7a3aef0ffae116bad65651c4a79bf
BLAKE2b-256 652a35980b61d83da7041d5444bf607bde9425e88228f80959aa2782c43a4a40

See more details on using hashes here.

File details

Details for the file pystack_manager-0.9.4a0-py2.py3-none-any.whl.

File metadata

  • Download URL: pystack_manager-0.9.4a0-py2.py3-none-any.whl
  • Upload date:
  • Size: 17.4 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

Hashes for pystack_manager-0.9.4a0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 18a22c7c4ce6b4951480a77548571c083c14a58dfa28f178730907b3dda52262
MD5 707f6cc117d2b3229e5aa4c6862982d4
BLAKE2b-256 2da1c34d086347f58c84420fddc3d75e3e55883a8c41d2143003ca90a016cd79

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page