Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Simple question: I would like to dynamically specify a list of 3 elements, {x,y,z}. Then I'd like to find that list, or any of its permutations, in a parent data set. The parent data set is composed of lists which are at least 3 elements long (like mine), but could also be 4 or 5 elements long. I will then be dynamically deleting the entire part which has an occurrence of x,y,z or z,x,y etc. from the parent data set (list of lists).

The first way I tried doesn't work for obvious reasons (I've removed Dynamic functionality because it doesn't work anyway):


As you can see, I want this to find and delete the 3rd and 4th elements, so that {{0,0,0},{1,1,1}} is returned. I'd also like to update {x,y,z} dynamically.

Are there any tricks to make this work? Or am I doing it entirely wrong? Thanks!

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Here is a simple way. It's not particularly fast, but may be fast enough for your purposes.

data = {{0, 0, 0}, {1, 1, 1}, {1, 2, 3}, {3, 2, 1, 9}};
subseq = Sort@{3, 1, 2};
DeleteCases[data, {___, a_, b_, c_, ___} /; Sort[{a, b, c}] == subseq]
(* {{0, 0, 0}, {1, 1, 1}} *)
share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.