Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: position lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg68712] Re: position lists
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Thu, 17 Aug 2006 04:18:18 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <ebujvu$6lu$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

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
> 
Hi Igor,

I am not sure whether this might be what you are looking for,

(Flatten[Position[a, #1]] & ) /@ Range[4]

--> {{1, 2, 5}, {3, 4}, {}, {6}}

HTH,
Jean-Marc


  • Prev by Date: Complexity of quantifier elimination
  • Next by Date: RE: position lists
  • Previous by thread: Re: position lists
  • Next by thread: RE: position lists