Consider if you would the case where we have some list of elements:
list0 = {54, 4, 7, 9, 3, 54, 4, 20, 2, 456, 2, 3};
And we have some target list:
targetList = {2, 3, 4, 7};
We'd like to scan from left to right through list0 and chop off an RHS tail at the moment all elements in targetList have appeared. With the example given we would have:
list0chopped = {54, 4, 7, 9, 3, 54, 4, 20, 2};
As an output.
Is there a simple way to do this?
If[Intersection[list0, targetList] == Sort@targetList, ...]– Chris Degnen Dec 24 '14 at 16:07Positionacross a list; see: (25591). You can avoid that by usingPositionIndexas I did in my answer. However since since my answer is otherwise very similar +1. – Mr.Wizard Dec 24 '14 at 20:16