dictree

Tree structure with dict interface and wildcard feature


License
MIT
Install
pip install dictree==1.1.0

Documentation

dictree

perth Build

About

Tree structure with dict interface and wildcard feature.

Example

from dictree import Dictree, WILDCARD

elt = Dictree()
elt[()] = 'apple'
elt[1, 2] = 'orange'
elt[1, WILDCARD] = 'banana'
elt[1, 2, 3] = 'grape'
elt[1, 2, 4] = 'peach'
"""
[apple]--1-->[]--2-->[orange]--3-->[grape]
              |                |
              |                |-4--> [peach]
              |--*-->[banana]
"""

for k, v in elt.items():
    print(k, v)  # (), apple
                 # (1, 2), orange
                 # (1, WILDCARD), banana
                 # (1, 2, 3), grape
                 # (1, 2, 4), peach

print(elt[1, 2])  # orange
print(elt[1, 3])  # banana
print(elt[1, 4])  # banana
print(elt[(1,)])  # raises KeyError