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: Raymond Hettinger <python@rcn.com>
Date: Tue Jan 31 2006 - 17:31:05 CET

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

Very nice. Here's a refinement:

>>> sets.sort(key=len)
>>> reduce(set.intersection, sets[1:], sets[0])
set(['c'])
Received on Tue Feb 7 20:23:20 2006