Last active
February 11, 2019 23:13
-
-
Save theriverman/6afd4f545f3d74c4413d51a0c1e9fbaa to your computer and use it in GitHub Desktop.
Recursively find keys in Python dictionary
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_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