Skip to content

Instantly share code, notes, and snippets.

@pykong
Last active November 12, 2017 15:44
Show Gist options
  • Save pykong/e86355166c23a9663047ff8dca2334db to your computer and use it in GitHub Desktop.
Save pykong/e86355166c23a9663047ff8dca2334db to your computer and use it in GitHub Desktop.
Note that if the second argument, i.e. None is not given, KeyError is raised if the key is not in the dictionary. Providing the second argument prevents the conditional exception. This is unlike the mydict.get() method, which defaults to None. https://stackoverflow.com/questions/15411107/delete-a-dictionary-item-if-the-key-exists
mydict.pop("key", None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment