I have two list:
main_list = [\'Smith\', \'Smith\', \'Roger\', \'Roger-Smith\', \'42\']
master_list = [\'Smith\', \'Roger\']
I want to coun
A one liner
>>>sum(any(m in L for m in master_list) for L in main_list)
4
Iterate over main_list
and check if any
of the values from master_list
are in that string. This leaves you with a list of bool values. It will stop after it finds one and so adds only one to the count for each string. Conveniently sum
counts all the True
s to give you the count.