Last Updated: February 25, 2016
·
540
· mahmoudhossam

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']