Skip to content

Instantly share code, notes, and snippets.

@landonstewart
Created May 11, 2018 19:51
Show Gist options
  • Save landonstewart/768afb1998a3c9cbcfa8e8bf7f054471 to your computer and use it in GitHub Desktop.
Save landonstewart/768afb1998a3c9cbcfa8e8bf7f054471 to your computer and use it in GitHub Desktop.
Find's the value of a key matching key in dictionary recursively
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