LeetPy
v0.2.1
디버깅은 처음에 코드를 작성하는 것보다 두 배나 어렵습니다.
데이터 구조 및 알고리즘 (DSA)과 관련된 문제를 해결하면 이진 트리 및 지시 된 그래프와 같은 복잡한 데이터 구조를 디버그하는 것이 얼마나 실망 스러운지 알고 있습니다.
LeetPy 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 - 데이터 구조의 표현을 터미널에 인쇄하려면