2
$\begingroup$

A simple question: I have a list

lis = {a,b,c,d,e,f,c,d}

I need to delete all the items in the list that occur before the first appearance of "c,d" to make:

res = {c,d,e,f,c,d}

Drop doesn't seem to help here.

$\endgroup$
1
  • $\begingroup$ lis /. {s___, c, d, e___} :> {c, d, e} $\endgroup$
    – Bob Hanlon
    Oct 6 at 1:13
2
$\begingroup$
First@
  SequenceCases[lis, {c, d, __}]

(* Out: {c, d, e, f, c, d} *)
$\endgroup$
1
  • $\begingroup$ It's slow for a long list, but it works. Thanks. $\endgroup$
    – Suite401
    Oct 6 at 1:35

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.