How to add a key:datum pair to the dictionary

Emile van Sebille emile at fenx.com
Sun May 16 15:35:08 EDT 1999


You can use update:

>>> a={1:1,2:2}
>>> a.update({3:3})
>>> a
{3: 3, 2: 2, 1: 1}


--

Emile van Sebille
emile at fenx.com
-------------------


MK <mark_removethis_ at _removethis_btweng.krakow.pl> wrote in message
news:373f0ee9.30600632 at news.tpnet.pl...
> Hello everyone,
>
> I have stumbled across a stupid problem: how to add a pair to
> dictionary like
>
> {'mk': {'repetitions': 20, 'no match': 10}}
>
> I have not found the method for this anywhere in documentation.
> Dictionary is mutable, but neither Library Reference nor Language
> Reference give information on how to _add_ something to dictionary.
> It seems strange -- I mean, is creating dictionary and then changing
> items in it the only possible method of changing dictionary? Can it be
> enlarged?
>
>
>
>
>
>
>
>
> MK
>
>
> --------------------------------------------------
> Reality is something that does not disappear after
> you cease believing in it - VALIS, Philip K. Dick
> --------------------------------------------------
>
> Delete _removethis_ from address to email me






More information about the Python-list mailing list