I have a String and a list defined as below
my_string = 'she said he replied'
my_list = ['This is a cool sentence', 'This is another sentence','she said hello he replied goodbye', 'she replied', 'Some more sentences in here', 'et cetera et cetera...']
I am trying to check if at least 3 words in my_string
exists in any of the strings in my_list
. The approach i'm taking is to split my_string
, and use all
to do the matching. However, this only works if all the items in my_string
exist in a sentence from my_list
if all(word in item for item in my_list for word in my_string.split()):
print('we happy')
1- How can I make it so the condition is satisfied if at least 3 items of my_string
are present in the sentence list?
2- Is it possible to match only the first and last word in my_string
in the same order? i.e "she" and "replied" are present in 'she replied' at index 3 of my_list
, return True.