Skip to content

zlliu246/pprint_tree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pprint_tree

prints tree (where nodes have multiple children) in human readable format

Installation

pip install pprint_tree

Quickstart

from typing import Any

class Node:
    def __init__(self, val: Any):
        self.val = val
        self.children = []

    def adopt(self, *val_list: list[Any]):
        for val in val_list:
            self.children.append(Node(val))

    def __getitem__(self, index: int) -> "Node":
        return self.children[index]
    
root = Node("root")
root.adopt("apple", "orange", "pear", "pineapple")
root[0].adopt("banana", "durian")
root[1].adopt("juice")
root[1][0].adopt("juice2")
root[1][0][0].adopt("potato", "soup")
root[2].adopt("kiwi", "avocado")
root[2][1].adopt("cherry tomato", "soup")


from pprint_tree import pprint_tree

pprint_tree(root)

"""
          _____________________________________root________________________________
          |                       |                   |                           |
   _____apple______             orange          _____pear_______________     pineapple
   |              |               |             |                      |
banana         durian           juice         kiwi          ________avocado__________
                                  |                         |                       |
                          _____juice2______          cherry tomato                soup
                          |               |
                       potato           soup
"""

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages