Coder Social home page Coder Social logo

drawtree's People

Contributors

erotemic avatar msbanik avatar pratted avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

drawtree's Issues

the drawtree installed by pip can not be imported

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

siblings nodes' height are not the same?

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.

Does not work for Huffman trees

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.

bintrees

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.