append to the end of a dictionary

Fredrik Lundh fredrik at
Tue Jan 24 15:50:18 CET 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:


More information about the Python-list mailing list