Skip to main content

print-btree

This packages allows you to print and visualize your binary tree

from print_btree import print_btree

class Node:
    def __init__(self, val):
        self.val = val
        self.left = None
        self.right = None

root = Node(1)
root.left = Node(2)
root.right = Node(3)
root.left.left = Node(4)
root.left.right = Node(5)

print_btree(root)

'''

 __1__
 |   |
_2_  3 
| |    
4 5   

'''

Ideally, your Node definition should be something like:

class Node:
    def __init__(self, val):
        self.val = val
        self.left = None
        self.right = None

But it's ok if your Node has different attribute names:

from print_btree import print_btree

class BNode:
    def __init__(self, value):
        self.value = value
        self.left_node = None
        self.right_node = None

root = BNode(1)
root.left_node = BNode(2)
root.right_node = BNode(3)
root.left_node.left_node = BNode(4)
root.left_node.right_node = BNode(5)
root.right_node.right_node = BNode(100)

print_btree(root, 
            val='value',
            left='left_node',
            right='right_node')

'''

 __1__
 |   |
_2_  3__
| |    |
4 5   100

'''

It's ok if you values are longer

from print_btree import print_btree

class Node:
    def __init__(self, val):
        self.val = val
        self.left = None
        self.right = None

root = Node('apple')
root.left = Node('pie')
root.right = Node('juice')
root.left.left = Node('pear')
root.left.right = Node('pineapplejuice')
root.right.right = Node('durian')

print_btree(root)
'''
       ________apple________
       |                   |
 _____pie_____           juice_
 |           |                |
pear   pineapplejuice       durian

'''

Metadata

Release files for print-btree 0.0.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for print-btree 0.0.14
File Size Uploaded Provenance Actions
print_btree-0.0.14.tar.gz 4.6 kB Without provenance Details for print_btree-0.0.14.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for print-btree 0.0.14
File Interpreter ABI Platform Actions
print_btree-0.0.14-py3-none-any.whl Python 3 none any Details for print_btree-0.0.14-py3-none-any.whl

Total release size: 10.0 kB

Security for print-btree 0.0.14

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page