Adding to a Dictionary

Kevin Altis altis at semi-retired.com
Sun Jan 26 13:09:31 EST 2003


http://www.python.org/doc/current/lib/typesmapping.html

myDict['key'] = 'value'

If you only want to set a dictionary item if it doesn't already exist, then
use setdefault.

ka

"Keenan Crane" <kcrane at uiuc.edu> wrote in message
news:3E3421E8.4050303 at uiuc.edu...
> 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')
>
> Are dictionaries even mutable?  If not, how do you usually solve this
> problem?
>
> Thanks,
>
> Keenan Crane
> kcrane at uiuc.edu
>






More information about the Python-list mailing list