Recently in a Python webinar, someone asked me how to check if any element in a list is present in another list using Python. This made me research more about this topic, after experimenting and testing various methods I found three effective methods to accomplish this task. In this article, I will explain all important methods with examples.
Check if Any Element in a List is Present in Another List using Python
Imagine you’re working on a project that involves analyzing customer data for a large e-commerce company based in the United States. You have two lists: one containing the email addresses of customers who purchased in the last month, and another list with the email addresses of customers who subscribed to the company’s newsletter. Your task is to find out if any customers who made a purchase are also subscribed to the newsletter.
Here’s an example:
purchasers = ["[email protected]", "[email protected]", "[email protected]", "[email protected]"]
subscribers = ["[email protected]", "[email protected]", "[email protected]", "[email protected]"]In this scenario, we need to check if any element from the purchasers list is present in the subscribers list.
Read How to Capitalize the First Letter of Every Word in a List using Python?
Method 1: Use the in Operator
One simple approach to check if any element from one list is present in another list is to use the in operator. The in operator returns True if an element exists in a list, and False otherwise. The ‘in’ operator checks if a specified item is present in the list.
Here’s an example:
purchasers = ["[email protected]", "[email protected]", "[email protected]", "[email protected]"]
subscribers = ["[email protected]", "[email protected]", "[email protected]", "[email protected]"]
for email in purchasers:
if email in subscribers:
print(f"{email} is present in both lists.")
break
else:
print("No common elements found.")Output:
[email protected] is present in both lists.You can see the output in the screenshot below.

In this code, we iterate over each email address in the purchasers list using a for loop. For each email, we check if it exists in the subscribers list using the in operator. If a match is found, we print a message indicating that the email is present in both lists and use the break statement to exit the loop. If no common elements are found after iterating through all the emails, the else block is executed, and we print a message indicating that no common elements were found.
Check out How to Find the Index of the Maximum Value in a List using Python?
Method 2: Use set Operations
Another efficient approach to check for common elements between two lists is to use set operations. In Python, a set is an unordered collection of unique elements. By converting the lists to sets, we can leverage the intersection operation to find the common elements.
Here’s how we can use set operations to solve our problem:
purchasers = ["[email protected]", "[email protected]", "[email protected]", "[email protected]"]
subscribers = ["[email protected]", "[email protected]", "[email protected]", "[email protected]"]
purchasers_set = set(purchasers)
subscribers_set = set(subscribers)
common_emails = purchasers_set.intersection(subscribers_set)
if common_emails:
print("Common elements found:")
for email in common_emails:
print(email)
else:
print("No common elements found.")Output:
Common elements found:
[email protected]You can see the output in the screenshot below.

In this code, we convert the purchasers and subscribers lists to sets using the set() function. Then, we use the intersection() method to find the common elements between the two sets. The resulting common_emails set will contain the email addresses that are present in both the purchasers and subscribers sets.
Finally, we check if the common_emails set is non-empty. If it is, we print a message indicating that common elements were found and iterate over the set to print each common email address. If the set is empty, we print a message stating that no common elements were found.
Read How to Get the Length of a String in Python?
Method 3: Use List Comprehension
List comprehension is a concise way to create new lists based on existing lists. We can use list comprehension to check if any element from one list is present in another list and create a new list containing the common elements.
Here’s an example:
purchasers = ["[email protected]", "[email protected]", "[email protected]", "[email protected]"]
subscribers = ["[email protected]", "[email protected]", "[email protected]", "[email protected]"]
common_emails = [email for email in purchasers if email in subscribers]
if common_emails:
print("Common elements found:")
for email in common_emails:
print(email)
else:
print("No common elements found.")Output:
Common elements found:
[email protected]You can see the output in the screenshot below.

In this code, we use a list comprehension to create a new list called common_emails. The list comprehension iterates over each email address in the purchasers list and checks if it exists in the subscribers list using the in operator. If an email is found in both lists, it is included in the common_emails list.
After creating the common_emails list, we check if it is non-empty. If it is, we print a message indicating that common elements were found and iterate over the list to print each common email address. If the list is empty, we print a message stating that no common elements were found.
Read How to Check if a String is Empty in Python?
Performance Considerations
When working with large lists, the performance of the chosen method becomes important. Let’s analyze the performance of each method:
Using the in Operator:
- Time complexity: O(n * m), where n is the length of the first list and m is the length of the second list.
- This method iterates over each element in the first list and checks if it exists in the second list, resulting in nested loops.
Using set Operations:
- Time complexity: O(n + m), where n is the length of the first list and m is the length of the second list.
- Converting lists to sets takes O(n + m) time, and the
intersectionoperation takes O(min(n, m)) time on average. - This method is more efficient than using the
inoperator, especially for large lists.
Using List Comprehension:
- Time complexity: O(n * m), where n is the length of the first list and m is the length of the second list.
- List comprehension iterates over each element in the first list and checks if it exists in the second list, resulting in nested loops.
- The performance is similar to using the
inoperator.
Based on the performance analysis, using set operations is generally the most efficient approach when dealing with large lists.
Check out How to Split a Python List Into Evenly Sized Chunks?
Conclusion
In this tutorial, I explained how to check if any element in a list is present in another list using Python. I covered different methods such as using the in operator, set operations, and list comprehension. I also discussed how to performance considerations.
You may also like to read:
- How to Write a List to a File in Python?
- How to Select Items from a List in Python?
- How to Add Tuples to Lists in Python?

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.