Reshma NirmalKumar Reshma NirmalKumar - 3 months ago 15
Python Question

How to match every word in the list having single sentence using python

how to match the below case 1 in python.. i want each and every word in the sentence to be matched with the list.

l1=['there is a list of contents available in the fields']
>>> 'there' in l1
False
>>> 'there is a list of contents available in the fields' in l1
True

Answer

Simple way

l1=['there is a list of contents available in the fields']
>>> 'there' in l1[0]
True

Better way wil be to iterate to all element of list.

l1=['there is a list of contents available in the fields']
print(bool([i for i in l1 if 'there' in i]))