I read the answers to how to get all occurrences of a key within nested dicts and lists here:
Apart from getting the value of the key, I would like to be able to distinguish values when multiple values are found in the nested structure. That means that the method output should include the "branch-path" to each of the matched values.
o = { 'temparature': '50',
'logging': {
'handlers': {
'console': {
'formatter': 'simple',
'class': 'logging.StreamHandler',
'stream': 'ext://sys.stdout',
'level': 'DEBUG'
}
},
'loggers': {
'simpleExample': {
'handlers': ['console'],
'propagate': 'no',
'level': 'INFO'
},
'root': {
'handlers': ['console'],
'level': 'DEBUG'
}
},
'version': '1',
'formatters': {
'simple': {
'datefmt': "'%Y-%m-%d %H:%M:%S'",
'format': '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
}
}
},
'treatment': {'second': 5, 'last': 4, 'first': 4},
'treatment_plan': [[4, 5, 4], [4, 5, 4], [5, 5, 5]]}
So in the dictionary example above, if I wanted the value of "console" I suggest to get a list of tuples containing one element:
[(["logging", "handlers", "console"],
{'formatter': 'simple', 'class': 'logging.StreamHandler', 'stream': 'ext://sys.stdout', 'level': 'DEBUG'})]
Is it possible to include that functionality in the method i linked to?