python - Query items in nested dictionaries with wildcards -


i trying retrieve items in nested dictionaries , print them out text game coded python 3 wildcards.

here dictionary:

dict = {     "ninja1": {         "no": "there map under blue rock"     },     "amy": {         "yes": "the peasant's name ato"     } } 

i loop through dictionary , print strings (like: 'there map..) if key 'yes'.

for key in dict:     if dict[wildcard] == 'yes':         print (dict[wildcard]['yes']) 

i new @ this, i'm sure codes horrible. appreciated!

all need test presence of key; use in operator:

for key in yourdict:     if 'yes' in yourdict[key]:         print(yourdict[key]['yes']) 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -