1

I have two lists:

 lst1 = {a,b,c,d,b,e,c}

and:

 lst2 = {b,c}

I am interested in removing all occurrences of lst2 from lst1, producing:

res = {a,d,b,e,c}

This is not exactly the same as Removing elements from a list which appear in another list; thank you for any thoughts.

Suite401
  • 4,793
  • 8
  • 18

1 Answers1

1

Somehow this does not work (according to the documentation it should, or please tell me what I am doing wrong)

SequenceCases[lst1, lst2 ->{}, Overlaps -> True]

A work around would be first computing the positions to be deleted:

toBeDeleted = Flatten[Range[Sequence @@ #] & /@ SequencePosition[lst1, lst2, Overlaps -> True], 1]

And then delete these positions:

Delete[lst1, {#} & /@ toBeDeleted]

Frank Martin
  • 1,145
  • 6
  • 17