Answers for "python how to check string occurence between two list"

1

python how to check string occurence between two list

'''I know this is an old question, but if anyone was wondering how to get matches or the length of the matches from one or more lists. you can do this as well.'''

a = [1,2,3]
b = [2,3,4]
c = [2,4,5]

'''To get matches in two lists, say a and b will be'''
d = [value for value in a if value in b] # 2,3 

'''For the three lists, will be'''
d = [value for value in a if value in b and value in c] # 2
len(d) # to get the number of matches

#also, if you need to handle duplicates. it will be a matter of converting the list to a set beforehand e.g
a  = set(a) # and so on
Posted by: Guest on April-13-2021

Code answers related to "python how to check string occurence between two list"

Python Answers by Framework

Browse Popular Code Answers by Language