+ 3
Nested dictionary and comprehension in python
i have a nested dictionary in the following form: dict = {"0":{ }, "1":{ }, "2":{ }, "3":{ }, ... } the inner dictionaries have various keys, not necessarily uniform, eg: dict["0"] = {"name" : "bruce", "age" : 28, ...} dict["1"] = {"name" : "eve", "sex" : "female", ...} I'm interested in creating a one-liner that decides if a specific name is present or not, eg: name_check = True if "bruce" in dict[<any>]["name"] I understand you can't access nested dicts like this, but is there a simple way w/o loops?
4 Respuestas
+ 2
Does this meet ur request?
https://code.sololearn.com/ci6GUYr0TvKz/?ref=app
+ 1
w/o means without, so even though your code does what I asked, it's not what I'm looking for :/
can you think of how to do this with no loops?
+ 1
you should do this with loops unless you are working with really small dicts. you could use keys as index numbers for the data to use less resources with looping.
0
rdhelli
Edited.
Check again