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.
_______________________________________________
Python-ideas mailing list
Python...@python.org
http://mail.python.org/mailman/listinfo/python-ideas
You should actually be using 3.1 if you are not.
> The two ideas floated were:
> od = ['a':1, 'b':2, 'c':3] # [ ] imply order, the ':' implies key-value
Interesting idea, but this would mean making ordered dict a fundamental
builtin type that all implementations must include rather than a
somewhat optional module import. I do not think it qualifies, at least
not yet.
>
> or
>
> od = o{'a':1, 'b':2, 'c':3} # { } imply dict, o implies order
>
> Apologies if this is the wrong place for this discussion.
Perfect place for such idea.
Terry Jan Reedy
I think we want to see it get some more field testing as part of the
collections module before bringing it into the core of the language is
seriously considered. If it's popular and useful, then doing so is
definitely a possibility though.
The history of the set builtin (i.e. first introduced in a module, then
made a builtin, then given literal syntax) is indicative of the kind of
time frames we're talking about here.
Rather than immediately jumping to a literal though, it might prove to
be more fruitful to explore the use of an ordered dictionary for keyword
arguments. Without that, convenient shortcuts like "OrderedDict(a=1,
b=2, c=3)" would never become possible.
Cheers,
Nick.
--
Nick Coghlan | ncog...@gmail.com | Brisbane, Australia
---------------------------------------------------------------
> This was discussed in mid June. Guido said -100.
Indeed. See http://mail.python.org/pipermail/python-ideas/2009-June/thread.html#4916
and http://mail.python.org/pipermail/python-ideas/2009-June/004924.html
How about something like:
od = OrderedDict.from_literal("""
{'a': 1, 'b': 2} """)
Of course, you need to hook/reimplement a full-blown parser :)
this would eliminate the [ ]:
def odict(*items):
return OrderedDict(items)
od = odict(('a', 1), ('b', 2))
well, 2 chars isn't much. however, I don't think its worth the effort.
Or:
def odict(*items):
iteritems = iter(items)
return OrderedDict(zip(items, items))
od = odict('a',1, 'b',2)
Not worth it either :)
--
Arnaud