I have the following dict:
{ 'foo': { 'name': 'bar', 'options': None, 'type': 'qux' }, 'baz': { 'name': 'grault', 'options': None, 'type': 'plugh' }, }
The names of the top level keys are unknown at runtime. I am unable to figure out how to get the name of the top level key where the value of type is plugh. I have tried all kinds of iterators, loops, comprehensions etc, but i'm not great with Python. Any pointers would be appreciated.
type
plugh
Try iterating over the dict keys and check for the element
for key in d: if(d[key]['type'] == 'plugh'): print(key)
baz
1.4m articles
1.4m replys
5 comments
57.0k users