To check if a list of words is in a string using Python, the easiest way is with list comprehension.
>>> list_of_words = ["this","words","string"]
>>> string = "this is a string with words."
>>> print([word in string for word in list_of_words])
[True, True, True]
>>>
If you want to check if all words of a list are in a string, you can use list comprehension and the Python all() function.
>>> list_of_words = ["this","words","string"]
>>> string = "this is a string with words."
>>> print(all([word in string for word in list_of_words]))
True
>>>
If you want to check if any of the words of a list are in a string, then you can use the Python any() function.
>>> list_of_words = ["this","words","string"]
>>> string = "this is a string with words."
>>> print(any([word in string for word in list_of_words]))
True
>>>
标签:word,String,Python,List,list,words,True,string From: https://www.cnblogs.com/MoKinLi/p/16999871.html