A Python library to implement various data structures.
Project description
collections-plus
A Python library implementing various data structures.
Installation
You can install this package using pip:
pip install collections-plus
and import the library with
import collections_plus
Please note that this code is in a pre-alpha state and will likely contain bugs.
Basic Usage and Examples
Currently, collections-plus supports Linked Lists. Briefly speaking, a linked list is a data structure where each node stores both a value and a pointer to the next node. This makes insertions and removals near the start very fast, at the expense of slower indexing.
To create a Linked List, first import the class:
from collections_plus import LinkedList
Then, you can create a Linked List like so:
my_llist = LinkedList(1, 2, 3, "pi", 4)
Or, if you have an existing list, you can unpack it:
sample_list = [1, 4, 3, 4]
sample_ll = LinkedList(*sample_list)
LinkedLists support most things you can do with a good old Python list. For instance, you can index into, mutate, and delete nodes (unfortunately, slicing is not implemented as of version 0.1.0):
indexed = my_llist[1] # indexed = 2
my_llist[2] = "approx pi" # sets value to "approx pi"
del my_llist[1]
print(my_llist) # LinkedList(1, "approx pi", "pi" 4)
Notably, you can pop, append, and insert:
sample_ll.pop() # returns 1
print(sample_ll) # LinkedList(4, 3, 4)
sample_ll.pop(2) # returns 4
print(sample_ll) # LinkedList(4, 3)
sample_ll.append("game")
print(sample_ll) # LinkedList(4, 3, 'game')
sample_ll.insert(0, "lost")
print(sample_ll) # LinkedList('lost', 4, 3, 'game')
Generally, pop, append, and insert will most often be used to implement
a FILO or FIFO queue. Please note that insert(-1, val) will also be slower than
append(val) because of the linked list structure.
This package also supports a variety of other functions that work very similar to their equivalents for default lists:
len(llist)llist.extend(other)llist.count(val)llist.index(val)llist.remove(val)llist.copy()- Binary comparators
==,!=,<,<=,>,>= - Operators
+and*
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 collections_plus-0.1.1.tar.gz.
File metadata
- Download URL: collections_plus-0.1.1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/5.15.153.1-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22cfa686227e2fe060c47cf2699bdaed9cf19796704384d09ac0ab1944dbf71e
|
|
| MD5 |
ff6614648057f30759fc8c62b3b3af59
|
|
| BLAKE2b-256 |
6cd7e98233def93b1deceda9e1b10fe283d46454e323093a2b0c59ac5556d665
|
File details
Details for the file collections_plus-0.1.1-py3-none-any.whl.
File metadata
- Download URL: collections_plus-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/5.15.153.1-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa386d2c1f1d4d65092df12f795c23688d890f83e6a74bf1ce9dc6031f2373b9
|
|
| MD5 |
9bd2f29d7a2e3bc588735220fb3f22af
|
|
| BLAKE2b-256 |
6eb4b06c7365d03e8a53f638076bc3b5017765c4dad9d9c12622393af3d221e2
|