Skip to content

Instantly share code, notes, and snippets.

@lv10
Created December 20, 2018 16:02
Show Gist options
  • Save lv10/95da2fb17d143b647d8a4aa6f8eb6019 to your computer and use it in GitHub Desktop.
Save lv10/95da2fb17d143b647d8a4aa6f8eb6019 to your computer and use it in GitHub Desktop.
Python Search key in a Nested Dictionaries
def _recursive_key_path(dictionary, key_to_find, key_path=[]):
if key_to_find in key_path:
return key_path
else:
for key, value in dictionary.items():
if key == key_to_find:
key_path.append(key)
return recursive(value, key_to_find, key_path)
if isinstance(value, dict):
key_path.append(key)
return recursive(value, key_to_find, key_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment