MathGroup Archive 2006

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

Search the Archive

RE: position lists


Igor,

What's the problem? It seems that all you have to do is Flatten the inner
lists.

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

Flatten@Position[a, #1] & /@ Range[4]
{{1, 2, 5}, {3, 4}, {}, {6}}

I don't see much that is simpler.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/

From: rych [mailto:rychphd at gmail.com]
To: mathgroup at smc.vnet.net


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: Re: position lists
  • Next by Date: Re: Product over an arbitrary index.
  • Previous by thread: Re: position lists
  • Next by thread: Re: position lists