Blog Rizauddin
And He found you lost and guided [you]. [93:7]
Pages
Home
Python
LaTeX
Linux
Windows
Travelog
About
Sunday, April 26, 2009
The intersection of two Python lists
Suppose that you have two lists, x and y. You can list out the items that are common to the two lists.
>>> x = [1,2,3,4,5]
>>> y = [2,6,7,3]
>>> [i for i in y if i in x]
[2, 3]
To see how many items found in the intersection.
>>> len([i for i in y if i in x])
2
Newer Post
Older Post
Home