On Wednesday 04 July 2007, David Abrahams wrote: > 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 > else: > 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.
>>> 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. -- Regards, Thomas Jollans GPG key: 0xF421434B may be found on various keyservers, eg pgp.mit.edu Hacker key <http://hackerkey.com/>: v4sw6+8Yhw4/5ln3pr5Ock2ma2u7Lw2Nl7Di2e2t3/4TMb6HOPTen5/6g5OPa1XsMr9p-7/-6
signature.asc
Description: This is a digitally signed message part.
-- http://mail.python.org/mailman/listinfo/python-list