LeetPy
v0.2.1
デバッグは、そもそもコードを書く方が2倍難しいです。
データ構造とアルゴリズム(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 - データ構造の表現を端末に印刷する