Re: "expanding a list"

• To: mathgroup at smc.vnet.net
• Subject: [mg57881] Re: [mg57860] "expanding a list"
• From: János <janos.lobb at yale.edu>
• Date: Sat, 11 Jun 2005 03:35:37 -0400 (EDT)
• References: <200506100629.CAA15653@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```On Jun 10, 2005, at 2:29 AM, Mark Coleman wrote:

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

In[1]:=
realst = Table[Random[Real,
{0, 1}], {i, 10}]
Out[1]=
{0.03511701775322186,
0.705212355575097,
0.6872307166505668,
0.8832229225445591,
0.4979794496000192,
0.11640215667914437,
0.7490677658059693,
0.8352690475872514,
0.09008175864152665,
0.1772237316561382}

In[2]:=
intlst = {5, 3}
Out[2]=
{5, 3}

In[5]:=
lst = First[Last[
Reap[i = 0; While[
i++ < Length[realst],
If[i == 1, Sow[
Table[realst[[i]],
{j, intlst[[1]]}]],
Sow[Table[realst[[
i]], {j, intlst[[
2]]}]]]]]]]
Out[5]=
{{0.03511701775322186,
0.03511701775322186,
0.03511701775322186,
0.03511701775322186,
0.03511701775322186},
{0.705212355575097,
0.705212355575097,
0.705212355575097},
{0.6872307166505668,
0.6872307166505668,
0.6872307166505668},
{0.8832229225445591,
0.8832229225445591,
0.8832229225445591},
{0.4979794496000192,
0.4979794496000192,
0.4979794496000192},
{0.11640215667914437,
0.11640215667914437,
0.11640215667914437},
{0.7490677658059693,
0.7490677658059693,
0.7490677658059693},
{0.8352690475872514,
0.8352690475872514,
0.8352690475872514},
{0.09008175864152665,
0.09008175864152665,
0.09008175864152665},
{0.1772237316561382,
0.1772237316561382,
0.1772237316561382}}

```

• Prev by Date: Solve
• Next by Date: Re: Mouse controlled 3D rotations
• Previous by thread: "expanding a list"
• Next by thread: Re: "expanding a list"