Skip to main content
edited title
Link
user64494
  • 29.1k
  • 4
  • 29
  • 56

selective Selective deletion of list members

Tweeted twitter.com/StackMma/status/1317797592496037889
Became Hot Network Question
Source Link
Suite401
  • 5k
  • 9
  • 20

selective deletion of list members

I have a list and need to remove certain members of the list.

lis = {f1,a,b,c,d,f2,e,g,h,i,f1,j,k,l,m,f2,n,o}

I need to remove each occurrence of f1 and the following two elements, and remove each occurrence of f2 and the following element. (f1 and f2 will always at least two elements apart). This gives:

res = {c,d,g,h,i,l,m,o}

ReplaceList would seem to be useful, but I am not able to see it. Thanks for any suggestions.