On Thu, Dec 23, 2021 at 05:23:00PM -0000, Stefan Pochmann wrote:
> Multiple times I wished that sets had an `intersects` method. Simply
> the negation of the `set.isdisjoint` method.
There are so many ways to get this:
def intersects(a, b):
return not a.isdisjoint(b)
Not ever one-line function needs to be built-in. Or take advantage of
the fact that empty sets are falsey and non-empty sets are truthy:
if a.intersection(b): ...
If you need lazy, bail-out early processing:
if any(el in a for el in b): ...
The problem is, there are so many easy, obvious ways to test for
intersection, that it seems hardly worth the effort to add it to the set
API. If we add it to set, we'd have to add it to frozenset, and the
three dict views (keys, values, items); anyone who has their own custom
set types would need to add it to their classes in order to keep the set
API.
That's not to say that we can't or won't add this method, but we have to
way up the costs against the benefits.
--
Steve
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/7T7VEKYLOQDZWIVDY5RUDKIELMLTH5EK/
Code of Conduct: http://python.org/psf/codeofconduct/