Recommended Free Tools
Use any(item in second_list for item in first_list) to get a Boolean indicating whether two lists share at least one value. Python stops at the first match; if there is no match—or the first list is empty—the expression returns False.
Check whether the lists share at least one value
For a one-off check or modest lists, combine Python’s any() function with the in membership operator:
As an Amazon Associate I earn from qualifying purchases.
first_list = ["apple", "pear", "plum"]
second_list = ["orange", "pear"]
has_common_item = any(item in second_list for item in first_list)
print(has_common_item) # True
The expression tests each item from first_list against second_list. any() returns True as soon as one membership test succeeds, so it does not need to check the remaining items. If every test fails, it returns False. An empty first_list also produces False, because there is no item to match. Python defines in as a membership test and its Boolean operations short-circuit. Python Language Reference: Membership test operations.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Choose list membership or a set for repeated checks
Use lists for a simple, one-time check
The direct expression is usually the clearest choice when the lists are small or you only need to check once. A list membership test may scan through the searched list, however, so doing it repeatedly can add up as the inputs grow.
#1 Best Overall
Build a set when you will reuse the searched values
If you will check many items against the same list, convert that list to a set once and reuse it:
second_set = set(second_list)
has_common_item = any(item in second_set for item in first_list)
The CPython time-complexity reference classifies list membership as O(n) and set membership as O(1) on average, with O(n) as the worst case for set membership. Creating the set also takes time and memory proportional to the input. It is therefore more likely to be useful for larger inputs or repeated lookups than for a single check on small lists. These complexity figures describe CPython, not a guarantee for every Python implementation. Python Wiki: Time Complexity.
Rank #2
Return matching values instead of a Boolean
If you need the common values, choose the approach based on whether order and duplicates matter.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Get unique common values
Set intersection returns the shared values as an unordered set, with duplicates removed:
common_items = set(first_list) & set(second_list)
has_common_item = bool(common_items)
The conversion requires every element to be hashable. A set is useful when unique matches are the goal, but it does not preserve list order or duplicate counts.
Keep the first list’s order and repeated matches
Filter the first list to retain each item that appears in the second:
matching_items = [item for item in first_list if item in second_list]
This preserves the order and duplicate occurrences from first_list. It uses list membership for each item; if performance matters and the searched values are hashable, use a set for membership while retaining the original list for the output:
second_set = set(second_list)
matching_items = [item for item in first_list if item in second_set]
Understand what counts as a match
- Equality, not just the same object: For built-in containers, membership tests compare by identity or equality. A value can match an equal value even when it is a different object. Python Language Reference: Membership test operations.
- Dictionary membership checks keys: If the searched object is a dictionary,
item in dictionarytests whetheritemis a key, not whether it is one of the dictionary’s values. Useitem in dictionary.values()when values are what you mean to search. - Sets need hashable elements: Lists and dictionaries cannot be placed directly in a set. Keep list membership, or compare a hashable representation such as a tuple or an ID field.
- Match records by the intended field: If two records should count as the same when their
idfields match, compare those fields explicitly rather than comparing the entire records.
Performance at a glance
| Method | Useful when | Cost and behavior |
|---|---|---|
any(x in second_list for x in first_list) |
Inputs are small or the check is one-off | In CPython, each list membership can scan O(n) values; uses ordinary membership semantics. |
Build second_set, then test membership |
You will reuse the searched values or have larger inputs | Set construction costs time and memory; membership is O(1) average and O(n) worst case in the cited CPython reference. Requires hashable elements and removes duplicates from the set. |
set(first_list) & set(second_list) |
You need unique common values | Builds both sets and a result; output is unordered and unique. |
O(n) describes growth with the number of elements, not a measured runtime. The complexity classifications above come from CPython documentation and should not be treated as a benchmark or as a promise about every Python implementation. Python Wiki: Time Complexity.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




