Re: expanding a list
- To: mathgroup at smc.vnet.net
- Subject: [mg42614] Re: [mg42593] expanding a list
- From: Tomas Garza <tgarza01 at prodigy.net.mx>
- Date: Fri, 18 Jul 2003 05:25:08 -0400 (EDT)
- References: <200307170745.DAA23026@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
The first thing that comes to my mind (and no doubt it will be much improved by other members of this group) is: In[1]:= a = MapThread[List, {plist, flist}] Out[1]= {{0.252, 7}, {0.252, 5}, {0.257, 6}, {0.235, 4}} In[2]:= Flatten[(Table[#[[1]], {#[[2]]}] & ) /@ a] Out[2]= {0.252,0.252,0.252,0.252,0.252,0.252,0.252,0.252,0.252,0.252,0.252,0.252,0.\ 257,0.257,0.257,0.257,0.257,0.257,0.235,0.235,0.235,0.235} Tomas Garza Mexico City ----- Original Message ----- From: "Alan Kelly" <Alan.Kelly at tcd.ie> To: mathgroup at smc.vnet.net Subject: [mg42614] [mg42593] expanding a list > Hi all, > I believe that this is a rather elementary question, but I am not > aware of a simple, elegant and efficient solution. I have searched > the MathGroup archive, but with no success. > > I have two lists - both of the same length. The first contains a > list of probabilities. For example, suppose the list length is 4 > (although in practice it would be much longer) and is of the > following form: > plist = {0.252, 0.252, 0.257, 0.235}. > The second contains a list of integers: > flist = {7,5,6,4}. > I wish to take the first element of plist and replicate that value > using the first element of flist. Similarly for the remaining > elements. > I should finish with a list of length 7+5+6+4 or 22. > Any suggestion please. > Many thanks, > Alan Kelly > Trinity College Dublin > >
- References:
- expanding a list
- From: Alan Kelly <Alan.Kelly@tcd.ie>
- expanding a list