This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: OrderedDict constructor do not keep items order
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ADechaume, eric.snow, ezio.melotti, rhettinger
Priority: normal Keywords:

Created on 2012-10-18 09:33 by ADechaume, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg173247 - (view) Author: Antoine Dechaume (ADechaume) Date: 2012-10-18 09:33

from collections import OrderedDict
print OrderedDict(a=0,b=1,c=2)

I get
OrderedDict([('a', 0), ('c', 2), ('b', 1)])

I expected
OrderedDict([('a', 0), ('b', 1), ('c', 2)])
msg173248 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-10-18 09:38
This is documented at

"""The OrderedDict constructor and update() method both accept keyword arguments, but their order is lost because Python’s function call semantics pass-in keyword arguments using a regular unordered dictionary."""
msg173574 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2012-10-23 01:39
Thanks Ezio.
msg173581 - (view) Author: Antoine Dechaume (ADechaume) Date: 2012-10-23 06:20
I did read the docs before submitting, obviously my brain was not plugged in.
I am sorry for the noise.
msg182239 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2013-02-16 20:48
FWIW, I'm working toward making **kwargs an OrderedDict.  First step: issue #16991
Date User Action Args
2022-04-11 14:57:37adminsetgithub: 60480
2013-02-16 20:48:42eric.snowsetnosy: + eric.snow
messages: + msg182239
2012-10-23 06:20:37ADechaumesetmessages: + msg173581
2012-10-23 01:39:10rhettingersetnosy: + rhettinger
messages: + msg173574
2012-10-18 09:38:36ezio.melottisetstatus: open -> closed

nosy: + ezio.melotti
messages: + msg173248

resolution: not a bug
stage: resolved
2012-10-18 09:33:33ADechaumecreate