Append a new value to dict

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Mon Oct 13 09:14:15 EDT 2008


jdd:
> foo = {'bar': 'baz'}
> foo.update({'quux': 'blah'})

That creates a new dict, to throw it away. Don't do that. Use the
standard and more readable syntax:

> foo = {...}
> foo['quux'] = 'blah'

Bye,
bearophile



More information about the Python-list mailing list