[Python-Dev] Proposal: add odict to collections

Guido van Rossum guido at python.org
Sun Jun 15 19:50:13 CEST 2008


On Sun, Jun 15, 2008 at 1:03 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> Raymond Hettinger wrote:
>>
>> I don't favor one over the other.  Am just pointing-out that the proposal
>> is a little more complex than simply wishing for an ordered verion of a
>> dictionary and expecting that that wish is self-defining in a way the
>> matches everyone's intuition, use cases, and expectations.
>
> If you have an odict with first-insertion ordering, it's fairly trivial to
> convert it to a dictionary with last-insertion ordering:
>
> class odictlastinsertion(odict):
>  def __setitem__(self, k, v):
>      self.pop(k, None)
>      self[k] = v
>
> As you note, going the other way would be rather difficult, suggesting that
> the version ordered by the first key insertion is the more fundamental
> structure.
>
> A PEP would definitely be needed to thrash out those kind of issues and
> decisions though

Right.

Though on this particular issue, my gut instinct tells me that
first-insertion-order is more useful (matching your assertion above).

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list