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
  • 165
  • 1
  • 12
  • Don't forget you can upvote and accept answers. See [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers), thanks! – yatu Mar 27 '20 at 21:00

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
  • 131,796
  • 23
  • 122
  • 195
yatu
  • 80,714
  • 11
  • 64
  • 111