MathGroup Archive 2005

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

Search the Archive

Re: "expanding a list"


Mark Coleman schrieb:
> Greetings,
> 
> I'd like to construct a list as follows. Say I have a list of reals  
> {x1,x2,x3,...xn}, and another list of integers {r,s}. I'd like to  
> make a new list
> 
> {{x1,x1,x1,...},{x2,x2,x2....},{x3,x3,x3,...},....,{xn,xn,xn,...}},  
> where the first sublist is of length r, and the remaining sublists  
> are of length s.
> 
> 
> Thanks,
> 
> -Mark
> 
> 
> 
This code:

newList[xi_List, {n1_Integer, n2_Integer}] :=
  Join[{Table[First[xi], {n1}]}, (Table[#1, {n2}] & ) /@ Rest[xi]]

newList[{1, 2, 3, 4}, {5, 2}]

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

should do it.

-- 
Peter Pein
Berlin


  • Prev by Date: Re: "expanding a list"
  • Next by Date: Re: moving dingbats
  • Previous by thread: Re: "expanding a list"
  • Next by thread: Re: "expanding a list"