fork download
  1. import re
  2.  
  3. pattern = r"\b(duck|crow|hen|sparrow)\s+eats\b"
  4. list2 = [['The crow eats'], ['Hen eats blue seeds'], ['the duck is cute'], ['she eats veggies']]
  5.  
  6. res = [[re.sub(pattern, r"\1", s, 0, re.I) for s in lst] for lst in list2]
  7.  
  8. print(res)
Success #stdin #stdout 0.03s 9384KB
stdin
Standard input is empty
stdout
[['The crow'], ['Hen blue seeds'], ['the duck is cute'], ['she eats veggies']]