Skip to content

Instantly share code, notes, and snippets.

@bugcy013
Created October 9, 2020 03:17
Show Gist options
  • Save bugcy013/df97d2eadec3a5397bd2b228eaf69a4d to your computer and use it in GitHub Desktop.
Save bugcy013/df97d2eadec3a5397bd2b228eaf69a4d to your computer and use it in GitHub Desktop.
def keys_exists(element, *keys):
if not isinstance(element, dict):
raise AttributeError('keys_exists() expects dict as first argument.')
if len(keys) == 0:
raise AttributeError('keys_exists() expects at least two arguments, one given.')
_element = element
for key in keys:
try:
_element = _element[key]
except KeyError:
return False
return True
if __name__ == '__main__':
keys_exists(dict, key, key, key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment