Created
May 11, 2018 19:51
-
-
Save landonstewart/768afb1998a3c9cbcfa8e8bf7f054471 to your computer and use it in GitHub Desktop.
Find's the value of a key matching key in dictionary recursively
This file contains hidden or 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 find_key_in_dict(key, dictionary): | |
for k, v in dictionary.items(): | |
if k == key: | |
yield v | |
elif isinstance(v, dict): | |
for result in find_key_in_dict(key, v): | |
yield result | |
elif isinstance(v, list): | |
for d in v: | |
for result in find_key_in_dict(key, d): | |
yield result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment