[Python-ideas] `OrderedDict.sort`

Ethan Furman ethan at stoneleaf.us
Tue Sep 24 17:36:17 CEST 2013


On 09/24/2013 08:23 AM, Ram Rachum wrote:
> On Sep 24, 2013 4:42 PM, Ethan Furman wrote:
>> On 09/24/2013 05:27 AM, Ram Rachum wrote:
>>>
>>> I think that your mistake is defining OrderedDict as a dict sorting by insertion order. I see no reason to define it
>>> that way [...]
>>
>> Insertion order is the one that you either remember, or is lost.
>
> Ethan, you've misunderstood my message and given a correct objection to an argument I did not make.
>
> I did not argue against ordering by insertion order on init. I agree with that decision. I disagree with defining the
> entire class as an insertion ordering class and refusing to allow users to reorder it as they wish after it's created.

Two points:

   - What happens when a new element is added to the OrderedDict after the user sorts it?

   - If by 'init' you mean something like `d = OrderedDict(a=1, b=2, c=3)` --
     this does not preserve an insertion order as the keywords end up in a
     regular, unsorted dict that is passed to OrderedDict.__init__

--
~Ethan~


More information about the Python-ideas mailing list