Adding to a Dictionary

Alex Martelli aleax at aleax.it
Sun Jan 26 13:06:33 EST 2003


Keenan Crane wrote:

> I'm just starting out with Python and I'm having trouble figuring out
> how to add an entry to an already created dictionary.
> 
> I'm looking for something like
> 
> myDict.append('key', 'value')

myDict['key'] = 'value'

Assigning a value to a yet-nonexistent key adds the key, using exactly
the same syntax as you'd use to re-bind an already-existing key.

> Are dictionaries even mutable?  If not, how do you usually solve this
> problem?

Yes, dictionaries are mutable.


Alex





More information about the Python-list mailing list