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)
Python does not have some useful or important data structures, like linked list
, tree map
, just like STL in C++.
This library aims to provide a python counterpart of C++ STL.
1. Install
python3 -m pip install Python-Algorithm-pyal
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
is_none_or_empty
histogram_ascii
is_sorted
unique
cmp
split_data_by_func
eq
discrete_sample
group_by_key_fun
top_n
clamp
argmax
argmin
make_list
swap
rotate
copy_to
kth_smallest_element
lower_bound
upper_bound
reverse_in_place
sort_in_place
find_first_if
find_last_if
next_permutation
prev_permutation
factorial
combinatorial_number
permutation_number
combinations_with_duplicate
longest_common_substr
top_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
File details
Details for the file python_algorithm_pyal-1.2.3.tar.gz
.
File metadata
- Download URL: python_algorithm_pyal-1.2.3.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97f933f3b3ffb350513092e98de07249f8891ee246d3a83726d6d74ae02f65eb |
|
MD5 | b36257f35460010793a4d6a7a1679877 |
|
BLAKE2b-256 | ae156decc727d0cf8d98759069f407baf4148a72f154e7f420052aaab8332d0b |
File details
Details for the file Python_Algorithm_pyal-1.2.3-py3-none-any.whl
.
File metadata
- Download URL: Python_Algorithm_pyal-1.2.3-py3-none-any.whl
- Upload date:
- Size: 23.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47137c99b6e5dd329ade5e9e36807a18b43167d9dae6dd68e6e6ca47aea61fd1 |
|
MD5 | fbc062b86a60014489614b9af1e90e59 |
|
BLAKE2b-256 | 380ceb224d09f4f430b321a1d25ae08ebdf4a7dcb392523e7ec2abb4325bfc7f |