Determine whether a key is present in a dictionary [duplicate]

if 'name' in mydict:

is the preferred, pythonic version. Use of has_key() is discouraged, and this method has been removed in Python 3.

Leave a Comment