This post will discuss how to find common elements from two lists in Python.

1. Using intersection() function

A simple and fairly efficient solution is to convert the first list into a set and then call the intersection() function. It returns a new set with elements common to the set with another iterable.

Download  Run Code

2. Using bitwise comparison

You can also use the operator-based counterpart of intersection(), which happens to be bitwise, and (&) operator. But this requires both arguments to be set, as shown below:

Download  Run Code

3. Using List Comprehension

Finally, you can find common elements from two lists using list comprehensions by searching each element of the first list in the second list. The time complexity of this solution is quadratic, and this is definitely not a recommended solution for large lists.

Download  Run Code

That’s all about finding the common elements from two lists in Python.