finding the intersection of a list of Sets

S

Suresh Jeevanandam

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

Is there any other shorter way?

Thanks in advance,
Suresh
 
P

Peter Otten

Suresh said:
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?
set(['c'])

Peter
 
R

Raymond Hettinger

That should have been:

The only refinement was the pre-sort based on set length.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top