A package that prints binary trees in terminal
Project description
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
'''
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
print_btree-0.0.9.tar.gz
(3.7 kB
view details)
Built Distribution
File details
Details for the file print_btree-0.0.9.tar.gz
.
File metadata
- Download URL: print_btree-0.0.9.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2dac4df61d00b4c5f5448ef2d7f13c5b942d1f7647b81fef61ad266f362fd077 |
|
MD5 | 0dce80ca6264f938b6d806c1192f8940 |
|
BLAKE2b-256 | 423a8e66538328447f37fc7eb2bac1faa412c0a0e6cc3748681cae95aaa4e3b7 |
File details
Details for the file print_btree-0.0.9-py3-none-any.whl
.
File metadata
- Download URL: print_btree-0.0.9-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29c49e394946a15e62fdd5611dfca7f2d6f752bd3aaa92a4ce163b180611f61d |
|
MD5 | 78336a1d3aeae5ea5323b89067514642 |
|
BLAKE2b-256 | ae32af015441372ea4db203e814c579f6769fb181ec754063dd75aab9acaf238 |