Python Practice › List Programs › Program 17
Do two lists share a member?
Write a Python program that returns True if two lists have at least one common member.
Input
[1, 2, 3] and [5, 3, 9]; [1, 2] and [7, 8]
Output
True False
Approach
- Two sets are disjoint when they share nothing.
Solution
def has_common(a, b): return not set(a).isdisjoint(b) print(has_common([1, 2, 3], [5, 3, 9]), has_common([1, 2], [7, 8]))Output
True False
Learn the concept
New to this topic? Read the lesson, then come back.