spkit.utils.view_hierarchical_order

spkit.utils.view_hierarchical_order(file_obj, sep=' ├── ', level=0, st='', show=True, return_str=False)

View nested dictionary type objects as hierarchical tree-order

View nested dictionary type objects as hierarchical tree-order

Parameters:
file_obj: dict-like
  • dictionary type object, object which has keys as attribuete

sep: str, default = ‘–>|’
  • seperation style

  • {’–>|’, ‘ ├──’ }

show:bool,
  • if false, then tree is not printed

return_str: bool, default=False
  • if true, return a printable-formated-string to reproduce tree order

Returns:
ststr

Tree-order as string, can be used to reproduce tree by print(st). if return_str is true

Examples

>>> #sp.utils.view_hierarchical_order
>>> import spkit as sp
>>> dObj = {'class 1':1, 'class 2':{'class 2.1':21, 
>>>        'class 2.2':{'class 2.2.1':4}},'class 3':3,
>>>        'class 4':{'class 4.1':41,}}
>>> sp.utils.view_hierarchical_order(dObj, sep='-->|')
|class 1
|class 2
|-->|class 2.1
|-->|class 2.2
|-->|-->|class 2.2.1
|class 3
|class 4
|-->|class 4.1
>>> sp.utils.view_hierarchical_order(dObj, sep=' ├──')
|class 1
|class 2
| ├──class 2.1
| ├──class 2.2
| ├── ├──class 2.2.1
|class 3
|class 4
| ├──class 4.1