append to the end of a dictionary

Rene Pijlman reply.in.the.newsgroup at my.address.is.invalid
Tue Jan 24 09:49:49 EST 2006


Yves Glodt:
>I seem to be unable to find a way to appends more keys/values to the end 
>of a dictionary

A dictionary has no order, and therefore no end.

>mydict = {'a':'1'}
>
>I need to append 'b':'2' to it to have:
>
>mydict = {'a':'1','b':'2'}
>
>How to do?

Like this:

>>> mydict = {'a':'1'}
>>> mydict['b'] = '2'
>>> print mydict
{'a': '1', 'b': '2'}
>>> {'a': '1', 'b': '2'} == {'b': '2', 'a': '1'}
True

-- 
René Pijlman



More information about the Python-list mailing list