PYthon Algorithms Library (pyal)
Unlike the STL in C++ which provides misceneous data structures, Python does not have some important structures, like linked list, tree map.
This library aims to provide a python counterpart of C++ STL.
1. Install
python3 -m pip install Python-Algorithm-pyal psutil pytz
2. Examples github
Balanced search tree based map, TreeMap
import pyal
def main():
tree_map = pyal.TreeMap()
data = [(0, "a"), (1, "b"), (2, "c"), (3, "d"), (4, "e"), (5, "f")]
for key, value in data:
tree_map[key] = value
key = -1
value = tree_map.get(key)
if value is None:
print(f"key={key} does not exist")
key = 0
print(f"key={key}, value={tree_map[key]}")
key = 1
node = tree_map.lower_bound(key)
print(f"lower_bound({key=}): {node.get()=}")
node = tree_map.upper_bound(key)
print(f"upper_bound({key=}): {node.get()=}")
print(f"min key: {tree_map.key_list_begin().get()}")
print(f"max key: {tree_map.key_list_end().prev().get()}")
Output
key=-1 does not exist
key=0, value=a
lower_bound(key=1): node.get()=1
upper_bound(key=1): node.get()=2
min key: 0
max key: 5
3. Popular data structures and algorithms.
Please check github for all examples.
-
Tree
-
List
-
String
- search_KMP
- search_multipatterns
- todo
-
Graph
- Graph
- Dijkstra
- topological_traversal
-
Common useful functions
binary_search- General binary search, binary_search(sorted_data, from, to, user_func), where user_func(x) defines the data as [False, ..., False, True, ..., True], this function returns the first position of 'True'.
- Many practical problems can be converted to this form, like binary_find, lower_bound, upper_bound, peak position in a rotated sorted array and etc.
is_none_or_emptyhistogram_asciiis_sorteduniquecmpsplit_data_by_funceqdiscrete_samplegroup_by_key_funtop_nclampargmaxargminmake_listswaprotatecopy_tokth_smallest_elementlower_boundupper_boundreverse_in_placesort_in_placefind_first_iffind_last_ifnext_permutationprev_permutationfactorialcombinatorial_numberpermutation_numbercombinations_with_duplicatelongest_common_substrtop_k_similar
Release files for Python-Algorithm-pyal 1.4.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| python_algorithm_pyal-1.4.5.tar.gz | 19.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| python_algorithm_pyal-1.4.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 44.1 kB
Release files / python_algorithm_pyal-1.4.5.tar.gz
| Download URL | python_algorithm_pyal-1.4.5.tar.gz |
|---|---|
| Size | 19.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f9b7457fe9997450061fd83f93b8a8d944649d45d33e916f121c632c6f60c54e
|
|
BLAKE2b-256 checksum How to use checksums |
90cd18e7454682bf7e3368e9038e8b354629fc468abc552dc1fb2c64b5b69d78
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / python_algorithm_pyal-1.4.5-py3-none-any.whl
| Download URL | python_algorithm_pyal-1.4.5-py3-none-any.whl |
|---|---|
| Size | 24.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
daea1e5aeaa925d78c626d26b449d9485e3c9c32ee9e7095713a7fc3036aa7b9
|
|
BLAKE2b-256 checksum How to use checksums |
27d5995c85d284bdea9cd7a1f76083b839046a6d5bb895140d5aac1634f1661d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|