PYthon Algorithm Library (pyal) targets at providing a python version substitue of STL in C++, such as linked list, tree map, and other data structures and popular algorithms.
Project description
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
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 python_algorithm_pyal-1.4.3.tar.gz.
File metadata
- Download URL: python_algorithm_pyal-1.4.3.tar.gz
- Upload date:
- Size: 23.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab7f3851e04b1dc72bd9bdec88350dc7f75b94397b5624dad676589a1baf7cf8
|
|
| MD5 |
b7812472896ea7d25ff0789a806cd088
|
|
| BLAKE2b-256 |
803425543743b6b627880f89481e8b4ec9d66594aa85560e28edcc1f1a185f43
|
File details
Details for the file python_algorithm_pyal-1.4.3-py3-none-any.whl.
File metadata
- Download URL: python_algorithm_pyal-1.4.3-py3-none-any.whl
- Upload date:
- Size: 31.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04a4e694f0846364aaecaf4e763ddd3963a564a0cc75ad273c0f4ede1a7159bd
|
|
| MD5 |
cedbb51ca556959b6e6887bbbe6d9c40
|
|
| BLAKE2b-256 |
d985d838b9a1346885f62db28203ab849dd5b4bcbf13a386ac01887eb0477a75
|