[Python-ideas] OrderedDict.insert()

Terry Reedy tjreedy at udel.edu
Wed Mar 25 17:46:04 CET 2015


On 3/25/2015 7:00 AM, Thomas Güttler wrote:
> I am missing OrderedDict.insert()
>
> Other people, too:
>
>
> http://stackoverflow.com/questions/16664874/how-can-i-add-the-element-at-the-top-of-ordereddict-in-python

I just added this answer, which I suspect covers move use cases.
===
If you know you will want a 'c' key, but do not know the value, insert 
'c' with a dummy value when you create the dict.

d1 = OrderedDict([('c', None), ('a', '1'), ('b', '2')])

and change the value later.

d1['c'] = 3




-- 
Terry Jan Reedy




More information about the Python-ideas mailing list