a dict trick
fdu.xiaojf at gmail.com
fdu.xiaojf at gmail.com
Thu Aug 2 02:51:52 EDT 2007
james_027 wrote:
> hi
>
> for example I have this dictionary
>
> dict = {'name':'james', 'language':'english'}
>
> value = 'sex' in dict and dict['sex'] or 'unknown'
>
> is a right pythonic of doing this one? I am trying to get a value from
> the dict, but if the key doesn't exist I will provide one.
>
> THanks
> james
>
value = your_dict.get(key, default_value)
More information about the Python-list
mailing list