I am trying to return True if a key already exists in the big dictinary or any subdictionary that is a part of this dict and False if it does not: here is my code:
def find_key(key, dicto):
for k, v in dicto.items():
if k == key:
return v
elif isinstance(v, dict):
for result in find_key(key, v):
return result
where am I going wrong ? here what i want :
data = {
"spam": {
"egg": {
"erwan": "Well..",
"a": "ezeaea",
"sausages": "Spam egg sausages and spam",
"jih": "je sais pas "
},
"oui": ''
}
}
find_key("oui", data) return True
find_key("jih", data) return True
find_key("oezea", data) return False