I need help looping through a list of sentences/strings, and erase the string characters forwards, based on another list with words.
sentences = ['im not george smith my name is lucas mangulu thank you',
'how shall i call you george smith oh okay got it'
'we have detected a miyagi chung in the traffic flow']
words = ['lucas mangulu', 'george smith', 'miyagi chung']
I know I have to loop for each element in the sentences list. But then I'm stuck on how to find() for example in the same element in the words list into the sentences list. So that the final results should be:
sentences = ['im not george smith my name is',
'how shall i call you'
'we have detected a']
#OR
sentences = ['im not george smith my name is lucas mangulu',
'how shall i call you george smith'
'we have detected a miyagi chung']
'my name is lucas mangulu thank you'.find('lucas mangulu')will return 11, which is the position of'lucas mangulu' in the string. From there you can use substring operation to extract what you need.['im not george smith my name is',you leftgeorge smithbut in the others you remove all names. Why?