 
 
 
 
 
 
Re: repeating elements in a list
- To: mathgroup at smc.vnet.net
- Subject: [mg54916] Re: repeating elements in a list
- From: Bill Rowe <readnewsciv at earthlink.net>
- Date: Sun, 6 Mar 2005 00:56:06 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
On 3/5/05 at 1:34 AM, torsten.coym at eas.iis.fraunhofer.de (Torsten
Coym) wrote:
>suppose I have list
>lst={A, B, C}
>and I want to create a new list, where all elements are repeated n
>times so that (for n=3):
>newlst={A, A, A, B, B, B, C, C, C}
>
>I have the following code to do this:
>n=3; newlst=Flatten[Table[Table[lst[[i]], {n}], {i, Length[lst]}]];
>but I'm pretty sure, that there must be a more elegant way to solve
>the problem.
Elegance is mostly in the eye of the beholder. But another way to achieve what you want would be
Flatten@Transpose[Flatten /@ NestList[List, lst, 2]]
--
To reply via email subtract one hundred and four

