Take the intersection of an arbitrary number of lists in python
Posted
by thepandaatemyface
on Stack Overflow
See other posts from Stack Overflow
or by thepandaatemyface
Published on 2010-05-23T21:19:19Z
Indexed on
2010/05/23
21:30 UTC
Read the original article
Hit count: 282
Suppose I have a list of lists of elements which are all the same (i'll use int
s in this example)
[range(100)[::4], range(100)[::3], range(100)[::2], range(100)[::1]]
What would be a nice and/or efficient way to take the intersection of these lists (so you would get every element that is in each of the lists)? For the example that would be:
[0, 12, 24, 36, 48, 60, 72, 84, 96]
© Stack Overflow or respective owner