I have the following list
a = ['Bananas', 'Ananas', 'Peach', 'Grapes', 'Oranges']
and the following list of lists
b = [['Bananas', 'Ananas', 'Peach', 'Grapes', 'Oranges'], ['Bananas', 'Ananas', 'Peach', 'Grapes', 'Oranges', 'Pear', 'Apple'], ['Oranges', 'Strawberry', 'Pear'], ... ]
As you can see, inside of b it's possible to have
- A list that's exactly the same as a
- A list with the same items as a but in a different order
- Similar to 1 and 2 but more items than a
- Similar to 1 and 2 but less items than a
- A totally different list than a
Considering that using
for value in b:
print(value)
one is able to get each list of b which can then be compared to a, how to know how many times cases 1, 2 and 3 occur (including duplicates)?
Inspired in this answer, I experimented
count_matches = 0
for value in b:
ff = str(value).strip("[]")
gg = str(a).strip("[]")
if gg in ff:
count_matches += 1
print(count_matches)
but this didn't work due to the order (for instances, other items could have been added in the middle).