Skip to main content

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

    • TreeMap example
      • Balanced binary search tree.
      • insert & delete: O(log N)
      • get: O(1)
    • DynamicHeap example
      • update & deletion: O(log N)
    • MinHeap, MaxHeap example
    • DisjointSet example
  • 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_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

Metadata

Release files for Python-Algorithm-pyal 1.4.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Python-Algorithm-pyal 1.4.4
File Size Uploaded Provenance Actions
python_algorithm_pyal-1.4.4.tar.gz 23.2 kB Without provenance Details for python_algorithm_pyal-1.4.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for Python-Algorithm-pyal 1.4.4
File Interpreter ABI Platform Actions
python_algorithm_pyal-1.4.4-py3-none-any.whl Python 3 none any Details for python_algorithm_pyal-1.4.4-py3-none-any.whl

Total release size: 55.0 kB

Release files / python_algorithm_pyal-1.4.4.tar.gz

Download URL python_algorithm_pyal-1.4.4.tar.gz
Size 23.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2276c210dc0bad291b35f28bcd41584e9b56794950a3dff3b68fcd1075d37214
BLAKE2b-256 checksum
How to use checksums
16b4e33bf6a096f17664bf835e05ab2f4807511ff9262b319c865a3e59a6959b
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.4-py3-none-any.whl

Download URL python_algorithm_pyal-1.4.4-py3-none-any.whl
Size 31.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8897a7e3e2c132cc4857180af07e07c6cec14b196850cc620ae394334ea8ffd1
BLAKE2b-256 checksum
How to use checksums
42ab623e5b3a847ada7d1805a4ccbb509b1bcd283ff39463818a17f33c7a52da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Security for Python-Algorithm-pyal 1.4.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page