The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Use any(item in second_list for item in first_list) to get a Boolean indicating whether at least one value in the first list is also in the second. It returns True at the first match and False if there is no match, including when the first list is empty.
Check for a match with any()
For a small list or a one-off check, combine Python’s any() function with the in membership operator:
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 generator expression checks each item from first_list against second_list. any() stops as soon as one membership test succeeds, so it does not check the remaining items after a match. Python defines in as a membership test, and its Boolean operations short-circuit; see the Python Language Reference on membership tests.
Free tools Windows power users keep installed
One-click scans. No signup required.
Choose the method for your data and result
For repeated checks, build a set once
If you will search the same second collection repeatedly, convert it to a set once and reuse it:
#1 Best Overall
second_set = set(second_list)
has_common_item = any(item in second_set for item in first_list)
In CPython’s complexity documentation, list membership is O(n); set membership is O(1) on average and O(n) in the worst case. Creating the set also takes time and memory proportional to the values it contains, so conversion is most useful when you reuse the set or search larger inputs. These complexity classifications describe CPython, not a guarantee for every Python implementation. See the Python wiki’s CPython time-complexity reference.
To return matching values, not just a Boolean
Use a list comprehension when you want matching values in the order they appear in first_list, including repeated matches:
Rank #2
matching_items = [item for item in first_list if item in second_list]
Use set intersection when only unique common values matter:
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchcommon_items = set(first_list) & set(second_list)
has_common_item = bool(common_items)
Set intersection creates an unordered set and removes duplicates. It builds sets from both inputs and allocates a result, so use it when the common values themselves are useful—not merely to answer a Boolean question.
Quick Recap
Best Value
Understand what counts as a match
- List membership checks whether an equal value is present; it does not require the exact same object instance. Built-in container membership uses identity or equality comparisons, as described in the Python Language Reference.
- For a dictionary,
item in some_dictchecks its keys, not its values. - Set members must be hashable. Lists and dictionaries cannot themselves be set members. If your elements are unhashable, keep list membership or compare a hashable value such as a tuple or an ID.
- For records such as dictionaries, compare the intended field explicitly. For example, to match records by ID, test their
idvalues rather than comparing whole records.
Compare the options
| Approach | Best fit | Trade-off |
|---|---|---|
any(x in second_list for x in first_list) |
Small inputs or a one-off Boolean check | In CPython, each list membership test may scan the second list. |
Convert the second list to a set, then use any() |
Larger searches or repeated checks against the same values | Set construction uses time and memory; members must be hashable. Set membership is O(1) on average and O(n) in the worst case in CPython. |
set(first_list) & set(second_list) |
Getting unique common values | Builds both sets; the result is unordered and has no duplicates. |
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.

