From: Bob Hanlon on

Use either Thread or Transpose

x = {1, 3, 5};

y = {2, 4, 6};

z = Thread[{x, y}]

{{1, 2}, {3, 4}, {5, 6}}

z = Transpose[{x, y}]

{{1, 2}, {3, 4}, {5, 6}}


Bob Hanlon

---- kevin <kevin999koshy(a)gmail.com> wrote:

=============
Hi Guys,

I am a newbie to mathematica..Is there anyway to read
values from 2 lists {n by 1} and {n by 1} to a new list {n by 2}
without using loops.. eg say you have x = {1,3,5} any y = {2,4,6}, I
will need a new list z ={{1,2},{3,4},{5,6}}.. Thanks in advance.




From: Srikanth K S on
*Dear Kevin,

This works:

Clear[list1,list2];
list1=={a,b,c};
list2=={d,e,f};
(*Suppose we always assume that lengths of the list are same*)
list3==Table[{list1[[i]],list2[[i]]},{i,1,Length[list1]}]

In case of lengths not being the same, it would be safe to use
'Min[Length[list1],Length[list2]]' instead of 'Length[list1]'

*---

2010/6/1 kevin <kevin999koshy(a)gmail.com>

> Hi Guys,
>
> I am a newbie to mathematica..Is there anyway to read
> values from 2 lists {n by 1} and {n by 1} to a new list {n by 2}
> without using loops.. eg say you have x == {1,3,5} any y == {2,4,6}, I
> will need a new list z =={{1,2},{3,4},{5,6}}.. Thanks in advance.
>
>
From: Peter Breitfeld on
kevin wrote:

> Hi Guys,
>
> I am a newbie to mathematica..Is there anyway to read
> values from 2 lists {n by 1} and {n by 1} to a new list {n by 2}
> without using loops.. eg say you have x = {1,3,5} any y = {2,4,6}, I
> will need a new list z ={{1,2},{3,4},{5,6}}.. Thanks in advance.
>

Transpose[{x,y}]

will do what you want.

//Peter
--
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de

From: Murray Eisenberg on
Easy -- at least in the kind of example you explicitly show:

x = {1, 3, 5}; y = {2, 4, 6};
Partition[Riffle[x, y], 2]
{{1,2},{3,4},{5,6}}

Riffle does the equivalent of a perfect "riffle shuffle" of two decks of
cards, alternating between the two:

Riffle[x, y]
{1, 2, 3, 4, 5, 6}

And then Partition[..., 2] splits that list into a list of length-two
sublists.

On 6/1/2010 4:24 AM, kevin wrote:
> Hi Guys,
>
> I am a newbie to mathematica..Is there anyway to read
> values from 2 lists {n by 1} and {n by 1} to a new list {n by 2}
> without using loops.. eg say you have x = {1,3,5} any y = {2,4,6}, I
> will need a new list z ={{1,2},{3,4},{5,6}}.. Thanks in advance.
>

--
Murray Eisenberg murrayeisenberg(a)gmail.com
80 Fearing Street phone 413 549-1020 (H)
Amherst, MA 01002-1912

From: becko on
An elegant way to do this is to use Transpose:


In[1]:= x = {1, 3, 5}; y = {2, 4, 6};

In[2]:= Transpose[{x, y}]

Out[2]= {{1, 2}, {3, 4}, {5, 6}}


--------------------------------------------------
From: "Murray Eisenberg" <murray(a)math.umass.edu>
Sent: Wednesday, June 02, 2010 1:04 AM
To: <mathgroup(a)smc.vnet.net>
Subject: Re: Assigning values to a list.

> Easy -- at least in the kind of example you explicitly show:
>
> x = {1, 3, 5}; y = {2, 4, 6};
> Partition[Riffle[x, y], 2]
> {{1,2},{3,4},{5,6}}
>
> Riffle does the equivalent of a perfect "riffle shuffle" of two decks of
> cards, alternating between the two:
>
> Riffle[x, y]
> {1, 2, 3, 4, 5, 6}
>
> And then Partition[..., 2] splits that list into a list of length-two
> sublists.
>
> On 6/1/2010 4:24 AM, kevin wrote:
>> Hi Guys,
>>
>> I am a newbie to mathematica..Is there anyway to read
>> values from 2 lists {n by 1} and {n by 1} to a new list {n by 2}
>> without using loops.. eg say you have x = {1,3,5} any y = {2,4,6}, I
>> will need a new list z ={{1,2},{3,4},{5,6}}.. Thanks in advance.
>>
>
> --
> Murray Eisenberg murrayeisenberg(a)gmail.com
> 80 Fearing Street phone 413 549-1020 (H)
> Amherst, MA 01002-1912
>
>