Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

Consider the below list of sets:

setlist = [s1,s2,s3...]

I need s1 ∩ s2 ∩ s3 ...

I can also compose a function to do it, just by performing a series of s1.intersection(s2), etc.

I just want to know is any better or recommended way?

1 Answer

0 votes
by (26.4k points)

From Python version 2.6 on you can utilize numerous arguments to set.intersection(), like    

u = set.intersection(s1, s2, s3)

In case, if the sets are in lists, then this will translate to:

u = set.intersection(*setlist)

Here. *a_list is a list expansion

Note that set.intersection is certifiably not static method, however this uses the useful notation to apply convergence of the first set with the remainder of the list. So if the argument list is vacant this will fizzle.

Are you interested to learn the concepts of python? Join the python training course fast!

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...