MathGroup Archive 2006

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

Search the Archive

Re: position lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg68897] Re: [mg68688] position lists
  • From: János <janos.lobb at yale.edu>
  • Date: Tue, 22 Aug 2006 05:20:48 -0400 (EDT)
  • References: <200608160736.DAA06180@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Aug 16, 2006, at 3:36 AM, rych wrote:

> have
>   In: a = {1, 1, 2, 2, 1, 4}
> want
>   {{1, 2, 5}, {3, 4}, {0}, {6}};
>
> more effectively than just
>   In: Position[a, #] & /@ Range[4]
>   Out: {{{1}, {2}, {5}}, {{3}, {4}}, {}, {{6}}}
>
> Ideas? Known one-liners?
> Thanks
> Igor

Not a one-liner, but gives a closer approximation to the desired result:

In[19]:=
Flatten[Last[Reap[i = 1;
      lenlst = Length[lst];
      While[i <= lenlst,
       Sow[Flatten[Position[
           lst, i]], i];
        i++; ], Range[
      Max[lst]]]], 2]
Out[19]=
{{1, 2, 5}, {3, 4}, {}, {6}}

János


---------------------------------------------------------
What is the difference between OS X and Vista ?

Microsoft employees are exited about OS X.

http://daringfireball.net/2006/04/windows_the_new_classic




  • Prev by Date: Re: Trigonometric simplification
  • Next by Date: Re: Need good reference for writing Stylesheets
  • Previous by thread: Re: position lists
  • Next by thread: Re: position lists