On Wed, 04 Jul 2007 16:18:58 +0200, Thomas Jollans wrote:
> On Wednesday 04 July 2007, David Abrahams wrote:
>> 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.
>
>>>> s1 = set(xrange(5))
>>>> s2 = set(xrange(3,9))
>>>> s1
> set([0, 1, 2, 3, 4])
>>>> s2
> set([3, 4, 5, 6, 7, 8])
>>>> s1 | s2
> set([0, 1, 2, 3, 4, 5, 6, 7, 8])
>>>> s1 & s2
> set([3, 4])
>>>>
>
> It's all in python already. And documented on the web too.
The OP already knows that but does not want to build a new `set`. He just
wants to know efficiently if the sets intersect without actually *doing*
the intersection.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list