MathGroup Archive 2006

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

Search the Archive

Re: position lists


a = {1, 1, 2, 2, 1, 4};

Flatten/@(Position[a,#]&/@
        Range[Max[a]])/.{}:>{0}

{{1,2,5},{3,4},{0},{6}}


Bob Hanlon

---- rych <rychphd at gmail.com> 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
> 


  • Prev by Date: calculate Recurrence Equations
  • Next by Date: Numerically eliminate quantifiers
  • Previous by thread: Re: position lists
  • Next by thread: Re: position lists