Python library to trace path of a particular key inside a nested dict
- For stable version
- pip install trace-dkey
- For developement
- git clone https://github.com/Agent-Hellboy/trace-dkey
- cd trace-dkey
- python -m venv .venv
- source .venv/bin/activate
>>> from trace_dkey import trace
>>> l={'a':{'b':{'c':{'d':{'e':{'f':1}}}}}}
>>> print(trace(l,'f'))
[['a', 'b', 'c', 'd', 'e', 'f']]
Now you can query it as l['a']['b']['c']['d']['e']['f']
>>> l['a']['b']['c']['d']['e']['f']
1
from trace_dkey import trace
l={'a':{'b':{'c':{'d':{'e':{'f':1}}}}}}
paths = trace(l,'f')
for path in paths:
dic = l
for key in path:
dic = dic[key]
print(dic)
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.