Proposal / Questions about OrderedDict literals and/or faster C implementation
I have a proposal for a literal syntax for OrderedDicts which is just replacing the braces with square brackets: ['a': 1,'b': 2] == OrderedDict([('a', 1),('b', 2)]) OrderedDict literals would follow: [x : x for x in foo()] == OrderedDict([(x,x) for x in foo()]) The rationale for the syntax is that it follows the set / list / dict precedent of curly braces for unordered collections, square brackets for ordered collections, and otherwise aping the normal dict syntax. OrderedDict is arguable one of the best recent additions to the Python standard library. Looking at the py3k codebase, it seems like adding OrderedDicts as a native C implementation at the same time as introducing a literal syntax with all the additions to the grammar and ast makes sense. A native implementation would make the memory usage closer to normal dicts (plus two pointers per element) but be potentially faster for many operations than even regular dictionaries and certainly much, much faster than the current Python-only implementation of OrderedDict. I've started working on this in my free time, but I'm not a seasoned CPython hacker. Any feedback or pointers would be helpful. Originally, I was planning on creating a patch first before suggesting this to the mailing list, but given the scope of the feature and the number of concerns I figure I might as well test the waters first. Even if the idea of a literal syntax is dismissed, I think a C implementation of OrderedDict would be a great addition and I'd love to help.
Hello, Thanks for wanting to contribute and welcome to python-dev :) Ideas are usually discussed first on python-ideas to assess usefulness, get the pulse of the community, beat the API into shape and such things before coming up to python-dev. (A number of core devs are on both lists.) You may want to search the mail archive for all the previous threads about adding a C version and literal notation for ordered dicts. Regards
On 2011-02-10, at 21:47 , Éric Araujo wrote:
Ideas are usually discussed first on python-ideas to assess usefulness, get the pulse of the community, beat the API into shape and such things before coming up to python-dev. (A number of core devs are on both lists.)
You may want to search the mail archive for all the previous threads about adding a C version and literal notation for ordered dicts.
Indeed, there's been a discussion on this very subject not three weeks ago: http://mail.python.org/pipermail/python-ideas/2011-January/009037.html I'm guessing this request is going to get more common for some time, as people are getting aware Ruby switched its Hash implementation to an ordered dict in 1.9 (well they didn't exactly switch anything around, they added back and next pointers to their dict cells)
participants (3)
-
Steve Goss
-
Xavier Morel
-
Éric Araujo