[Python-ideas] Ordered Dictionary Literals

Masklinn masklinn at masklinn.net
Wed Nov 11 17:44:12 CET 2009

On 11 Nov 2009, at 17:33 , Richard Saunders wrote:
> Hey All,
> We were exploring new features of Python 3.0 at our Tucson User's Group
> here in Tucson (TuPLE: Tucson Python Language Enthusiasts), in particular,
> the OrderedDict.  See
> http://groups.google.com/group/TuPLEgroup/browse_thread/thread/40af73f8e194a4f8
> Has there been any discussion about making a "better" OrderedDict literal? I
> did
> some googling and didn't find anything.
> Basically, the thought was there might be a place for a slightly better
> literal for OrderedDict
> in Python 3.0
> od = OrderedDict([('a',1),('b':2)])  # seems clumsy
> The two ideas floated were:
>  od = ['a':1, 'b':2, 'c':3]    # [ ] imply order, the ':' implies key-value
> or
>  od = o{'a':1, 'b':2, 'c':3}   # { } imply dict, o implies order
> Apologies if this is the wrong place for this discussion.  There has been
> a lot of opinions flying here at work and at TuPLE which I will be happy
> to share if this is the right place. ;)

The first one is, I think, pretty smart considering the built-in set syntax in 3.x is the same as the dict's, except without the colons ({1, 2, 3} is a set, {'a':1, 'b':2, 'c':3}).

Sadly (for the proposal) since PEP 3003 on the Python Language Moratorium (http://www.python.org/dev/peps/pep-3003/) was accepted there can be no change to the language's syntax until the end of the moratorium, and this would be a syntactic alteration of the language. Your only option is therefore to stash it until the end of the moratorium (maybe take the time to try it out/implement it, and submit a full PEP with a ready-made implementation when the moratorium ends).

Anyway, if you choose to take the time to implement a proof of concept during the moratorium, I personally prefer the first idea to the second one.

More information about the Python-ideas mailing list