I have a list of words
list1=['duck','crow','hen','sparrow']
and a list of sentences
list2=[['The crow eats'],['Hen eats blue seeds'],['the duck is cute'],['she eats veggies']]
I want to remove every occurance of the word 'eats' if it appears exactly after any of the words from the list.
desired output= [['The crow','Hen blue seeds','the duck is cute'],['she eats veggies']]
def remove_eats(test):
for i in test:
for j in i:
for word in list1:
j=j.replace(word + " eats", word)
print(j)
break
remove_eats(list2)
The replace method is not really working for the strings. Could you help me out? Is it possble with Regex?