[Python-ideas] kw to be ordered dict
Arek Bulski
arek.bulski at gmail.com
Sun Sep 4 16:06:44 EDT 2016
I have a piece of code that essentially reimplements OrderedDict. I have
been wondering why the key ordered is not preserved correctly (tests fail).
c = Container(a=1,b=2,c=3,d=4)
self.assertEqual(c.keys(), ["a","b","c","d"])
self.assertEqual(c.values(), [1,2,3,4])
self.assertEqual(c.items(), [("a",1),("b",2),("c",3),("d",4)])
Then I looked at collections.OrderedDict ctor docstring and it says
"Initialize an ordered dictionary. The signature is the same as regular
dictionaries, but keyword arguments are not recommended because their
insertion order is arbitrary."
I expected the **kw to reproduce the same order as actual keyword
arguments. The only right way to solve it, as it seems to me, would be to
make **kw an OrderedDict.
Arkadiusz Bulski
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160904/1f8c555f/attachment.html>
More information about the Python-ideas
mailing list