Skip to content

Instantly share code, notes, and snippets.

@theriverman
Last active February 11, 2019 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theriverman/6afd4f545f3d74c4413d51a0c1e9fbaa to your computer and use it in GitHub Desktop.
Save theriverman/6afd4f545f3d74c4413d51a0c1e9fbaa to your computer and use it in GitHub Desktop.
Recursively find keys in Python dictionary
def find_keys(dictionary: dict, key_name: str) -> list:
keys_list = []
def dict_recurse_search(_wh):
for k, v in _wh.items():
if k == key_name:
[keys_list.append(x) for x in v]
if isinstance(v, dict):
dict_recurse_search(v)
else:
continue
dict_recurse_search(dictionary)
return keys_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment