You are given two lists and need to return the elements that appear in both of them.
This problem is about shared membership, not about preserving duplicates. If a value appears multiple times in one list but only needs to be reported once as a common element, the final result should still contain that value only once. That is why list1 = [1, 1, 2] and list2 = [1, 3] returns [1], not [1, 1].
For example, if list1 = [1, 2, 3] and list2 = [2, 3, 4], the common elements are 2 and 3, so the answer is [2, 3]. If the lists do not overlap at all, like [1, 2] and [3, 4], the answer is an empty list.
So the task is to find the intersection of the two input lists and return the shared elements.
Example Input & Output
2 and 3 are present in both lists.
No common elements found.
Only 1 is common.
Algorithm Flow

Solution Approach
The most natural Python tool for this problem is the set. A set stores unique values and supports intersection directly, which lines up perfectly with the idea of "find the elements that appear in both collections."
The first step is to convert each input list into a set:
That conversion automatically removes duplicates, which is useful here because the problem wants common elements, not repeated copies of the same common element.
Once both inputs are sets, the shared values can be found with either set1 & set2 or set1.intersection(set2). The result is another set containing only the elements that appear in both inputs.
To match the expected return type, we can turn that back into a list:
One thing to remember is that sets do not preserve order, so the returned list may not come out in the same order every time unless you sort it. That is why some test harnesses compare sorted results instead of raw list order.
This approach is much cleaner than nested loops. A double loop would work, but it would check every element of one list against every element of the other. That becomes slower as the inputs grow. The set-based version instead turns the problem into fast membership and intersection operations that Python already supports well.
Another nice detail is readability. Using sets tells the reader immediately that duplicates do not matter and that we care about shared membership. That matches the exact meaning of the problem.
If you wanted to preserve first-list order, you would need a slightly different strategy, such as checking membership with a set but building the answer with a loop. But for this problem, the tests treat the answer more like a mathematical intersection, so the compact set version is a strong fit.
The runtime is about O(n + m) for input lengths n and m, assuming normal hash behavior, and the extra space is also proportional to the distinct elements stored in the sets.
Best Answers
def find_common(list1, list2):
s1 = set(list1)
s2 = set(list2)
return list(s1 & s2)Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
