append to the end of a dictionary

Fredrik Lundh fredrik at pythonware.com
Tue Jan 24 09:50:18 EST 2006


Yves Glodt wrote:

> I seem to be unable to find a way to appends more keys/values to the end
> of a dictionary... how can I do that?
>
> E.g:
>
> mydict = {'a':'1'}
>
> I need to append 'b':'2' to it to have:
>
> mydict = {'a':'1','b':'2'}

to add stuff to a dictionary, use item assignment:

    mydict["b"] = 2

dictionaries are unordered, so the items you add will appear at an arbitrary
location.  for more on this, see the tutorial:

http://www.python.org/doc/2.4.2/tut/node7.html#SECTION007500000000000000000

</F>






More information about the Python-list mailing list