LeetPy
v0.2.1
调试是首先写代码的两倍。
如果您解决了与数据结构和算法(DSA)有关的问题,则您将知道对复杂的数据结构(如二进制树和有向图)进行调试是多么令人沮丧。
LeetPy是一个轻巧的Python软件包,在解决DSA问题时会使您更有效。它包含实用程序功能和算法,使调试和测试变得更加容易。这是一些功能:
LeetPy提供了方便的print()功能,以显示您的结构的外观(所有终端内部!)。LeetPy的算法始终可以正常工作。 要安装最新的稳定版本,请运行:
$ pip install leetpy从最新的github提交中安装:
pip install git+https://github.com/aryanpingle/leetpy这是一个最少的用例:
# 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这是一个复杂的:
# 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为广泛的数据结构提供了广泛的实用程序功能。有关使用示例的全面列表,请访问 /examples/readme.md。
LeetPy计划支持以下数据结构:
所有数据结构都有一些常见的API:
create() -> structure - 基于某些参数创建带有随机数据和属性的结构export_as_code(structure) -> str获得一个独立的python3函数,当调用时,返回给定的数据结构export_as_svg(structure) -> None创建具有给定数据结构的SVG文件print(structure) -> None - 打印数据结构的表示终端