Check if Two Arrays Have At Least One Common Element using Python

any function and list comprehension

def containsAtLeastOneCommonElement(data1, data2):
    return any(i in data1 for i in data2)


result = containsAtLeastOneCommonElement([1, 6, 9], [5, 9, 12])
print(result)  # True

result = containsAtLeastOneCommonElement([2, 4, 8], [5, 9, 12])
print(result)  # False

Leave a Comment

Cancel reply

Your email address will not be published.