Re: How to create this kind of list
- To: mathgroup at smc.vnet.net
- Subject: [mg122132] Re: How to create this kind of list
- From: Helen Read <readhpr at gmail.com>
- Date: Sun, 16 Oct 2011 07:05:31 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <j7bm30$35r$1@smc.vnet.net>
On 10/15/2011 6:08 AM, Szymon Roziewski wrote: > Hello there, > I am thinking about creating such a list. > I have 2 lists with the same number of elements. > The idea is to create one list which was taken from these previous two ones > in the following way: > Take one element of the first list and one from another and put it into > result list {{x1,y1},{x2,y2},...,{xn,yn}}. > Input lists: > A={x1,x2,...,xn} > B={y1,y2,...,yn} > > All best, > Szymon Roziewski Here are two ways. (And BTW, it helps when you post here to include an example that others can copy/paste into Mathematica instead of having make up an example for you.) Anyway, let's make a couple of lists: list1 = RandomInteger[10, 5] list2 = RandomInteger[{15, 20}, 5] One method: Use Riffle to make a new list alternating elements from list1 and list2, then Partition into pairs, like so. Partition[Riffle[list1, list2], 2] Second method: Put list1 and list2 into matrix with list1 as the first row and list2 as the second row, then Transpose the matrix. Transpose[{list1, list2}] -- Helen Read University of Vermont