[Python-ideas] Ordered Dictionary Literals

Mathias Panzenböck grosser.meister.morti at gmx.net
Thu Nov 12 22:27:40 CET 2009


On 11/12/2009 05:46 PM, Antoine Pitrou wrote:
> Richard Saunders <richismyname at ...> writes:
>>
>> 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
>
> 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.



More information about the Python-ideas mailing list