MathGroup Archive 2006

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

Search the Archive

Re: Partition


KFUPM schrieb:
> 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
> 

Flatten[(Through[{First, Rest}[#1]] & ) /@ Partition[list, 5], 1]

or

Partition[list, 5] /. {(f_)?AtomQ, r__} :> Sequence[f, {r}]

are my first two ideas.

P²


  • Prev by Date: RE: Partition
  • Next by Date: Re: Re: List of user-defined derivatives
  • Previous by thread: RE: Partition
  • Next by thread: Re: Partition