Proposal: s1.intersects(s2)

David Abrahams dave at
Wed Jul 4 09:59:24 EDT 2007

Here's an implementation of the functionality I propose, as a
free-standing function:

        def intersects(s1,s2):
            if len(s1) < len(s2):
                for x in s1:
                    if x in s2: return True
                for x in s2:
                    if x in s1 return True
            return False

Right now, the only convenient thing to do is 

      if s1 & s2 ...

but that builds a whole new set.  IMO that query should be available
as a method of set itself.

Dave Abrahams
Boost Consulting

The Astoria Seminar ==>

More information about the Python-list mailing list