Steven D'Aprano wrote:
On Wed, 17 Jun 2009 04:28:29 am Terry Reedy wrote:
When you read OrderedDict([('a', '1'),('b', '2'), ('c', '3')]),
OrderedDict({'a':1', 'b':'2', 'c':'3'}]
Creating an ordered dict from arbitrarily ordered input data surely ranks up there with one of the most pointless operations ever!
You know, this is such a simple, yet silly, mistake to make, I'd be almost tempted to disallow constructing an OrderedDict from regular dicts. If you want non-arbitrary ordering, you can't use a dict as input, and if you don't want arbitrary ordering, there's no point in using an ordered dict!
As far as I can see, there is no use-case for OrderedDict(dict) other than to generate confused newbies.
How about ['a':'1', 'b':'2', 'c':'3']?
Nice Idea!
I hope you're being sarcastic.
If hard-coded ordered dicts are common enough then having syntactic sugar for them would be a good idea: ['a':'1', 'b':'2', 'c':'3'] is both shorter and clearer than OrderedDict([('a', '1'),('b', '2'), ('c', '3')]). I doesn't feel that unPythonic to me.
But ordered dicts tend to be built one item at a time while iterating through some data whose values aren't known until runtime, so I doubt that ordered dict literals would be common enough anyway to warrant addition.