An example of a stack in Python 3
Project description
Stack module
An example of a stack in Python 3
Example usage
import stackModule
from stackModule import stackTools
from random import randint as rand
stackOptions = {
'pointer': -1,
'size': 5,
'type': int
}
stackHandler = stackTools()
stackHandler.stackOptions = stackOptions
stackHandler.stack = stackHandler.initStack(stackOptions['size'],stackOptions['type'])
print(stackHandler.dump())
stackHandler.push(3)
print(stackHandler.dump())
for i in range (0,rand(0,30)):
try:
n=rand(0,651)
stackHandler.push(n)
print(f'Added {n}')
except stackmodule.StackFull: print("Stack got full")
print(stackHandler.dump())
print(stackHandler.pop())
print(stackHandler.dump())
stackHandler.push(5)
print(stackHandler.dump())
stack = stackHandler.dump()
print("The script exported the stack: "+str(stack))
Module features
Making a stack handler
stackHandler=stackTools(myStack,stackOptions)#Define our stack handler
A stack handler will simply hold the stackTools class with your stack and it's options
Initialise stack (initStack)
stack=stackHandler.initStack(5,int) # Initialise a new stack which can contain 5 integer values
Initialise stack will update the list that is acting as a stack to the correct size with the expected data format
This will most likely never be updated
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
stack-module-0.1.4.tar.gz
(2.8 kB
view details)
Built Distribution
File details
Details for the file stack-module-0.1.4.tar.gz
.
File metadata
- Download URL: stack-module-0.1.4.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15149528fcade882eb96e3ad2f33fc3c68e123e00d4af16eb9c2dddbb66a6096 |
|
MD5 | 7450850e5b4b6b7b20184726c3abdb28 |
|
BLAKE2b-256 | bd6165289cc684dad039d0917580f48958214b730b28de430a90940e6c6c4337 |
File details
Details for the file stack_module-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: stack_module-0.1.4-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3d6c702f1ce83c904a3b8151013422aa71566f53ed88aadeff120a292114350 |
|
MD5 | 8346d107a309d6484d5fb877fac5aefe |
|
BLAKE2b-256 | 8468299340443015a21f22ce8f63675f1572019ec2d599a4039a1e613f9477b5 |