msbanik / drawtree Goto Github PK
View Code? Open in Web Editor NEWDraw binary tree in plain text
Draw binary tree in plain text
is missing the cli definition on the setup.py
environment:
Python 3.6.4
pip 9.0.1
the Exception is:
ImportError: cannot import name 'draw_bst'
which from lib/python3.6/site-packages/drawtree/__init__.py
maybe the pypi package not be upgrade, it shows latest uploaded date is 2015-10-03, and version is drawtree 0.1.1
When I insert a string like: '[0.19, 2.95, ... ,9.57]' at draw_level_order function, it cannot draw the tree of float numbers.
Hi msbanik,
The library is pretty cool, but I wonder can siblings nodes' height be the same?
For example, code:
from drawtree import draw_level_order
draw_level_order('{3,9,20,1,2,15,17}')
it generates:
3
/ \
/ \
/ \
9 20
/ \ / \
1 2 / \
15 17
Can node 1,2 and node 15,17 be in the same level?
Thank you.
Hi,
drawtree
works for integer nodes. I was trying to draw a huffman tree with it - it gave an error when trying to do an int
conversion of a letter. The code is in deserialize
function:
nodes = [None if val == '#' else TreeNode(int(val))
for val in string.strip('[]{}').split(',')]
When I removed the int call, I got the tree. Is it not possible to support alphanumeric nodes by doing so?
Regards.
cool library! I'm using this along with the bintrees
library's AVLTree implementation
it's a pretty popular library - you might want to consider supporting it out of the box or adding a recipe to the readme
https://pypi.python.org/pypi/bintrees/2.0.2
here's how I use it:
from random import sample
from drawtree import drawtree
from bintrees.avltree import AVLTree, Node
class Tree(AVLTree):
def __init__(self, items):
items = {x:x for x in items} if isinstance(items, list) else items
super(Tree, self).__init__(items)
def display(self):
drawtree.drawtree(self._root)
Node.val = property(lambda self: self.value) # rename value to val for drawtree
items = sample(range(100), 10)
print items
tree = Tree(items)
root = tree._root
tree.display()
thanks for making this! I was surprised there were so few good implementations of an ascii binary tree
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.