Skip to content

Instantly share code, notes, and snippets.

@andyfangdz
Last active November 23, 2016 01:49
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 andyfangdz/27cf4d38b6bd831fc0dc0d70e0cb322c to your computer and use it in GitHub Desktop.
Save andyfangdz/27cf4d38b6bd831fc0dc0d70e0cb322c to your computer and use it in GitHub Desktop.
def safe_get(_dict, _key, _type):
val = _dict.get(_key, None)
try:
return _type(val)
except TypeError:
return _type()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment