3
$\begingroup$

The final task is to revise the question I posed at list rearrangement:

I now start with this list:

lis = {{1,2,3},{"True",3,4,5},{6,5},{3},{6,4},{"Truex",2,1},{5},{5,6},{7,8,9}}

I want to make a new list consisting of elements of lis that begin with "True" (or "True" followed by any further string characters), and include the next two elements directly following, thus making triplets:

res = {({"True",3,4,5},{6,5},{3}},{{"Truex",2,1},{5},{5,6}}}

Again the task seems to be to get SequenceCases to recognize the pattern that allows it to pick up elements with "True" as well as "True*" Thanks again for ideas.

$\endgroup$
1
  • 2
    $\begingroup$ SequenceCases[lis, {{_?(StringContainsQ[ToString@#, "True"] &), ___}, _, _}] $\endgroup$ Sep 22 at 18:56
4
$\begingroup$
SequenceCases[lis, {{_String?(StringMatchQ["True*"]), __}, _, _}]
{{{"True", 3, 4, 5}, {6, 5}, {3}}, {{"Truex", 2, 1}, {5}, {5, 6}}}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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