Git Product home page Git Product logo

leetpy's Introduction

LeetPy Banner

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: LeetPy provides convenient print() 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 parameters
  • export_as_code(structure) -> str - To get an independent Python3 function that when called, returns the given data structure
  • export_as_svg(structure) -> None - To create an SVG file with a visualization of the given data structure
  • print(structure) -> None - To print a representation of the data structure to the terminal

leetpy's People

Contributors

aryanpingle avatar

Stargazers

 avatar

Watchers

 avatar

leetpy's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.