Solution Exercise 21

Define a function overlapping() that takes two lists and returns True if they have at least one member in common, False otherwise. You may use your the in operator, but for the sake of the exercise, you should (also) write it using two nested for-loops. That two for-loops are nested means that one loop is placed inside the other loop.

#Solution using the in operator
def overlapping1(list1, list2):
    for item in list1:
        if item in list2:
            return True
    return False

#Solution using nested for-loops
def overlapping2(list1, list2):
    for item1 in list1:
        for item2 in list2:
            if item1 == item2:
                return True
    return False

def main():
    list1 = [1,2,3,4]
    list2 = [4,5,6,7]
    print(overlapping1(list1, list2))
    print(overlapping2(list1, list2))
    
if __name__ == '__main__':
    main()