1

I have the code that checks for at least one common item:

def common_members(list1, list2):
    for items1 in list1:
        for items2 in list2:
            if items1 == items2:

    return False

How do I revise this code such that it checks for TWO common items in two lists?

pancakes
  • 159
  • 1
  • 2
  • 14

1 Answers1

4

You can use sets to check how many items from several lists intersect:

len(set(items1).intersection(items2)) >= 2
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
yatu
  • 86,083
  • 12
  • 84
  • 139