Python @ DjangoSpin

PyPro #68 Finding common elements in lists

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon
Reading Time: 1 minutes

Finding common elements in lists in Python

Finding common elements in lists in Python

Write a Python program for finding common elements in lists.

Finding common elements in lists

listOne = [2, 4, 6, 8, 10, 12]
listTwo = [3, 6, 9, 12, 15]

commonElements = list( set(listOne) & set(listTwo) )		# Intersection operator & of sets

print(commonElements)			[12, 6]

See also:

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon

Leave a Reply