Image
# The get() method on dicts
# and its "default" argument

name_for_userid = {
    382: "Alice",
    590: "Bob",
    951: "Dilbert",
}

def greeting(userid):
    return "Hi %s!" % name_for_userid.get(userid, "there")

>>> greeting(382)
"Hi Alice!"

>>> greeting(333333)
"Hi there!"
 

If you'd like to learn more about how to apply this Python Trick then check out my article + video tutorial here:

>> https://dbader.org/blog/python-dict-get-default-value 

I hope this helps you out!

— Dan