Skip to content

Instantly share code, notes, and snippets.

@pallabpain
Created March 15, 2021 07:26
Show Gist options
  • Save pallabpain/7726e797e831fb6ca92316ba5f78c8b7 to your computer and use it in GitHub Desktop.
Save pallabpain/7726e797e831fb6ca92316ba5f78c8b7 to your computer and use it in GitHub Desktop.
Find a key in dictionary or a list of dictionaries
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