Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: Assigning values to a list.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg110108] Re: Assigning values to a list.
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Wed, 2 Jun 2010 02:04:59 -0400 (EDT)

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 at gmail.com
80 Fearing Street                    phone 413 549-1020 (H)
Amherst, MA 01002-1912


  • Prev by Date: How do make the output of Graphics[ ] print out in "Inch" units ?
  • Next by Date: fyi, for users of free Mathematica player on linux 64 bit OS
  • Previous by thread: Re: Assigning values to a list.
  • Next by thread: Re: Colored wire ContourPlot3d