Re: finding the intersection of a list of Sets
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: finding the intersection of a list of Sets

From: Peter Otten <__peter__@web.de>
Date: Tue Jan 31 2006 - 11:40:01 CET

Suresh Jeevanandam wrote:

> I have a list of sets in variable lsets .
> Now I want to find the intersection of all the sets.
>
> r = lsets[0]
> for s in r[0:]:
> r = r & s

Try to post working examples.

> Is there any other shorter way?

>>> sets = map(set, "abc bcd cde".split())
>>> reduce(set.intersection, sets)
set(['c'])

Peter
Received on Tue Feb 7 20:19:43 2006