On Tue, 17 Dec 2019 at 11:48, Paul Moore <p.f.mo...@gmail.com> wrote:

> On Tue, 17 Dec 2019 at 11:13, Larry Hastings <la...@hastings.org> wrote:
> > I lack this strongly mathematical view of sets others have espoused;
> instead I view them more like "dicts without values".  I'm therefore
> disgruntled by this inconsistency between what are I see as closely related
> data structures, and it makes sense to me that they'd maintain their
> insertion order the same way that dictionaries now do.
>
> I'll admit to a mathematical background, which probably influences my
> views. But I view sets as "collections" of values - values are "in"
> the set or not. I don't see them operationally, in the sense that you
> add and remove things from the set. Adding and removing are mechanisms
> for changing the set, but they aren't fundamentally what sets are
> about (which for me is membership). So insertion order on sets is
> largely meaningless for me (it doesn't matter *how* it got there, what
> matters is whether it's there now).
>
> Having said that, I also see dictionaries as mappings from key to
> value, so insertion order is mostly not something I care about for
> dictionaries either. I can see the use cases for ordered dictionaries,
> and now we have insertion order, it's useful occasionally, but it's
> not something that was immediately obvious to me based on my
> intuition. Similarly, I don't see sets as *needing* insertion order,
> although I concede that there probably are use cases, similar to
> dictionaries. The question for me, as with dictionaries, is whether
> the cost (in terms of clear semantics, constraints on future
> implementation choices, and actual performance now) is justified by
> the additional capabilities (remembering that personally, I'd consider
> insertion order preservation as very much a niche requirement).
>

As a random data point, I often see the pattern where one needs to remove
duplicates
from the list while preserving the order of first appearance.
This is for example needed to get stability in various type-checking
situations (like union items, type variables in base classes, type queries
etc.)

One can write a four line helper to achieve this, but I can see that having
order preserving set could be useful.
So again, it is "nice to have but not really critical".

--
Ivan
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/STQVILVCC7ECBRF53ZQCIWQS45IYOIKJ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to