I have two lists of strings. I want to compare all the items in list 1 to list 2 and then count the matches. Here's what I've tried:
count = 0
global_fruit = ['apples', 'bananas', 'pears', 'oranges', 'peaches', 'apricots', 'mangoes']
local_fruit = ['bananas', 'apricots', 'oranges']
if any(f in global_fruit for f in local_fruit):
count += 1
print(count)
This returns a count of 1 because the script exits as soon as it finds the first match in the second list. I want it to return a count of 3 because there are three matches between the lists.
Is there a way to do this? Order is not important.