Use get() with dict
Instead of directly accessing a dictionary using bracket syntax, use get() instead, get() returns none if they key isn't in the dictionary, direct access results in a KeyError.
Do this:
numbers.get('one')
Instead of this:
numbers['one']
Written by Mahmoud Hossam
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Related Tags
#python
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#