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.14.tar.gz
(4.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file print_btree-0.0.14.tar.gz.
File metadata
- Download URL: print_btree-0.0.14.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1125fcef1bdc3e5a616d53a999aabb89e353309c5a7e74e8016c0cfa40e081a7
|
|
| MD5 |
8d3ac64aa8a3c0972bc21bcd1c62ece1
|
|
| BLAKE2b-256 |
cf59b10a8676e771e02b89931a24c99ebfaf9c075b198789be13949abfb78723
|
File details
Details for the file print_btree-0.0.14-py3-none-any.whl.
File metadata
- Download URL: print_btree-0.0.14-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
295a2b6f73bfd21bf9b2700497b05164afe0c26fa585d7f163242dd31376f7d3
|
|
| MD5 |
6691bffed45a985e4cf79b28ddd7a07f
|
|
| BLAKE2b-256 |
1b124aaa3f9908790897462a85820cc433e2d7e88cedcc2da8c245ae9db4c38e
|