Created
December 20, 2018 16:02
-
-
Save lv10/95da2fb17d143b647d8a4aa6f8eb6019 to your computer and use it in GitHub Desktop.
Python Search key in a Nested Dictionaries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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