Debugging is twice as hard as writing the code in the first place.
If you solve problems related to Data Structures & Algorithms (DSA), you know how frustrating it is to debug complex data structures like Binary Trees and Directed Graphs.
LeetPy is a lightweight Python package that makes you more efficient when you solve DSA problems. It contains utility functions and algorithms that make debugging and testing SO MUCH easier. Here are some features:
- Several Data Structures: Binary Trees, Linked Lists, 2-D Arrays, etc.
- Visualize Your Objects:
LeetPyprovides convenientprint()functions that show you what your structure looks like (all inside your terminal!). - Save & Export: Serialization and export functions help you save an exact copy of your structure, and give you the code to generate them from scratch.
- Flexibility: Create your data structure however you want;
LeetPy's algorithms will always work correctly.
Installation
To install the latest stable release, run:
$ pip install leetpy
To install from the latest GitHub commit:
pip install git+https://github.com/aryanpingle/leetpy
Usage & Examples
Here's a minimal use-case:
# Create a random binary tree and visualize it
from leetpy import BinaryTree
root = BinaryTree.create(n=20) # create a random binary tree with 20 nodes
BinaryTree.print_structure(root) # visualize the binary tree
And here's a complex one:
# Suppose you want to 'save' 10 binary search trees (example: for testing purposes)
# You would need some Python code that generates each tree exactly
from leetpy import BinaryTree
for i in range(1, 11):
# Generate a random binary search tree (BST) with 20 nodes
# Each node should have a value between 1 and 10 (inclusive)
root = BinaryTree.create(n=20, min_val=1, max_val=10, make_bst=True)
# Get the python code that generates this exact BST
# Oh, and make each node an object of class "CustomNode"
# Oh, and keep indentation to 2 spaces
code += "\n" + BinaryTree.export_as_code(root, node_alias="CustomNode", indent=2)
with open("testing.py", "w") as f:
f.write(code)
LeetPy offers a wide range of utility functions - for a wide range of data structures. For a comprehensive list of usage examples, check out /examples/README.md.
Development
LeetPy has plans to support the following data structures:
- 1-D Arrays
- 2-D Arrays
- Binary Trees
- Singly Linked Lists
- Doubly Linked Lists
- Undirected Graphs (Weighted + Unweighted)
- Directed Graphs (Weighted + Unweighted)
All data structures have some common API's:
create() -> structure- To create the structure with random data and properties based on certain parametersexport_as_code(structure) -> str- To get an independent Python3 function that when called, returns the given data structureexport_as_svg(structure) -> None- To create an SVG file with a visualization of the given data structureprint(structure) -> None- To print a representation of the data structure to the terminal
Metadata
Release files for leetpy 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| leetpy-0.2.2.tar.gz | 19.9 kB | Without provenance | Details for leetpy-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| leetpy-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for leetpy-0.2.2-py3-none-any.whl |
Total release size: 41.8 kB
Release files / leetpy-0.2.2.tar.gz
| Download URL | leetpy-0.2.2.tar.gz |
|---|---|
| Size | 19.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d4556f40118f455ba90ab5f276a20d2fbd4bc422c572bbd6fa030fd799d87158
|
|
BLAKE2b-256 checksum How to use checksums |
6688770e7608ddf179de9aef8556c1246eaab789437e5fc6adc97073691afde7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.6
|
Release files / leetpy-0.2.2-py3-none-any.whl
| Download URL | leetpy-0.2.2-py3-none-any.whl |
|---|---|
| Size | 22.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ecb96322e4aed7c769180ef91d813d795b647e0a8e02ddd109b4d8ae36ec872e
|
|
BLAKE2b-256 checksum How to use checksums |
5420c404d491b44c48fc44993e481a4c250db1ab57ea53ec0bcfd53f0ad8744c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.6
|
Security for leetpy 0.2.2
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.