MathGroup Archive 2005

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

Search the Archive

Re: repeating elements in a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg54933] Re: repeating elements in a list
  • From: Peter Pein <petsie at arcor.de>
  • Date: Sun, 6 Mar 2005 01:32:43 -0500 (EST)
  • References: <d0dekq$lek$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Torsten Coym wrote:
> Hello,
> 
> 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.
> 
> 
> thank you
> 
Flatten[Table[#, {3}] & /@ lst, 1];

-- 
Peter Pein
Berlin


  • Prev by Date: Re: Kernel Problem
  • Next by Date: Re: repeating elements in a list
  • Previous by thread: Re: repeating elements in a list
  • Next by thread: Re: repeating elements in a list