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: Partition

  • To: mathgroup at smc.vnet.net
  • Subject: [mg71648] Re: Partition
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Sun, 26 Nov 2006 03:48:31 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <ek975q$fjq$1@smc.vnet.net>

KFUPM wrote:
> Dear All
> 
> I have a very large list of numbers that look like this: ( although the
> size is different)
> 
> list={a,b,c,d,e,f,g,h,i,j,k,l,m,n,o}
> 
> And i need to rewrite the list into
> 
> list2={a,{b,c,d,e},f,{g,h,i,j,},k,{l,m,n,o}}
> 
> Since my list is too big, i need Mathematica to do it for me regardless
> of the site of the list.
> 
> I would appreciate it if you can help me in this regard,
> 
> Thanks
> 
> KFUPM
> 
You could try

In[1]:=
list = {a, b, c, d, e, f, g, h, i, j, k, l, m, n, o};

In[2]:=
Flatten[Partition[list, 5] /. {(x_)?AtomQ, y__} -> {x, {y}}, 1]

Out[2]=
{a, {b, c, d, e}, f, {g, h, i, j}, k, {l, m, n, o}}

Regards,
Jean-Marc


  • Prev by Date: Re: Partition
  • Next by Date: SetPrecision vs N
  • Previous by thread: Re: Partition
  • Next by thread: Re: Partition