Created
March 15, 2021 07:26
-
-
Save pallabpain/7726e797e831fb6ca92316ba5f78c8b7 to your computer and use it in GitHub Desktop.
Find a key in dictionary or a list of 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 key_in_dict(d, k): | |
if isinstance(d, list): | |
for v in d: | |
return key_in_dict(v, k) | |
if isinstance(d, dict): | |
if k in d: | |
return True | |
for v in d.values(): | |
return key_in_dict(v, k) | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment