Re: finding the intersection of a list of Sets
- From: Peter Otten <__peter__@xxxxxx>
- Date: Tue, 31 Jan 2006 11:40:01 +0100
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
.
- Follow-Ups:
- Re: finding the intersection of a list of Sets
- From: Raymond Hettinger
- Re: finding the intersection of a list of Sets
- References:
- finding the intersection of a list of Sets
- From: Suresh Jeevanandam
- finding the intersection of a list of Sets
- Prev by Date: Re: Newbie question: Unicode hiccup on reading file i just wrote
- Next by Date: Re: test whether 2 objects are equal
- Previous by thread: finding the intersection of a list of Sets
- Next by thread: Re: finding the intersection of a list of Sets
- Index(es):