MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Extracting information from lists


Perhaps I don't fully comprehend your question, so I guess your problem
is to find the position of start of ALL the runs. So it could be a run
of 1's, or 3's, and you should be able to locate their starting
positions.
If that is so, I would do it like this:

whereRuns[l_] :=
  Position[
      Replace[
          Split[l],
          e_List?(Length[#] = 2 &) :> Prepend[Rest[e], xxx],
          2] // Flatten,
      xxx] // Flatten

The function locates the runs, it replaces their first element by xxx,
and returns the positions of that xxx's.

In:=
where[lst]

Out=
{6,10,16}


I didn't turn your 4th element, 6, into 1, as David Park did, so I
don't get the desired result, but I also think your question is not in
exact consistency with your result.

Bye,
Borut


  • Prev by Date: Re: Retaining variable/function expressions from session to session
  • Next by Date: Re: Retaining variable/function expressions from session to session
  • Previous by thread: Re: Extracting information from lists
  • Next by thread: Re: does this shut down anyone else's kernel?