in Python find number of same elements in 2 lists

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-03-23T13:17:40Z Indexed on 2010/03/23 13:23 UTC
Read the original article Hit count: 242

Filed under:
|
|

Hi, In Python if I have 2 lists say:

l1 = ['a', 'b', 'c', 'd']
l2 = ['c', 'd', 'e']

is there a way to find out how many elements they have the same. In the case about it would be 2 (c and d)

I know I could just do a nested loop but is there not a built in function like in php with the array_intersect function

Thanks

© Stack Overflow or respective owner

Related posts about python

Related posts about arrays