MathGroup Archive 2001

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

Search the Archive

Re: Best code to match corresponding list items?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg27741] Re: [mg27729] Best code to match corresponding list items?
  • From: "Mark Harder" <harderm at ucs.orst.edu>
  • Date: Wed, 14 Mar 2001 04:06:41 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Roger,
    Here's 2 ways of doing it:

In[293]:=
A = {a1, a2, a3};
B = {b1, b2, b3};
X = {c1, c2, c3};

In[296]:=Thread[List[A, B, X] ]
Out[296]={{a1, b1, c1}, {a2, b2, c2}, {a3, b3, c3}}

In[297]:=Transpose[{A, B, X}]
Out[297]={{a1, b1, c1}, {a2, b2, c2}, {a3, b3, c3}}

-Mark Harder


-----Original Message-----
From: Roger Ison <rison at ix.netcom.com>
To: mathgroup at smc.vnet.net
Subject: [mg27741] [mg27729] Best code to match corresponding list items?


>Given two lists
>A={a1,a2,a3,...}
>B={b1,b2,b3...}
>
>I want to produce the list
>C={  {a1,b1}, {a2,b2}, {a3,b3}...}  }
>as efficiently as possible.
>Better yet, generalize to do this with N lists all of same length.
>
>Obviously it can be done directly with Table, but is there a more elegant,
>implicit way to write it that doesn't involve passing a function to Table
>and using an explicit index? Is there a general functional primitive for
>this that I simply haven't found? Seems like something so common, there
>ought to be a built-in function for it.
>
>Thanks,
>Roger
>
>
>



  • Prev by Date: Re: Loading MultipleListPlot package
  • Next by Date: aesthetic ColorFunction for DensityPlots
  • Previous by thread: Re: Best code to match corresponding list items?
  • Next by thread: Re: Best code to match corresponding list items?