Re: Manipulating list
- To: mathgroup at smc.vnet.net
 - Subject: [mg101529] Re: [mg101486] Manipulating list
 - From: Leonid Shifrin <lshifr at gmail.com>
 - Date: Thu, 9 Jul 2009 01:58:22 -0400 (EDT)
 - References: <200907081113.HAA12448@smc.vnet.net>
 
MapThread[Prepend, {list2, list1[[All, 3]]}]
or
Flatten /@ Transpose[{list1[[All, 3]], list2}]
or
Module[{copy = list1}, copy[[All, {1, 2}]] = list2; RotateRight[copy, {0,
1}]]]
will do what you want. There are also many other ways of course. Note
that on (very) large lists, the last solution is by far the most efficient
of those
I listed (20 - 25 x faster on lists of length 100000 according to my tests).
Regards,
Leonid
On Wed, Jul 8, 2009 at 4:13 AM, kosal lee <leekosal at yahoo.com> wrote:
> Hello Mathematica users
>
> I am new to Mathematica and I have one particular problem I would like you
> to help me.
> Suppose I have two lists:
>
>    list1 = {{A,B,C},{D,E,F},{G,H,I}}
>    list2 = {{1,2},{3,4},{5,6}}
>
> I want to have the third elements in each of member list in list1 (that is,
> C,F,I) to appear in the first position in each member list in list2
>
> that is, i want to have  list ={{C,1,2},{F,3,4},{I,5,6}}
>
>  Thank you.
> Kosal
>
>
- References:
- Manipulating list
- From: kosal lee <leekosal@yahoo.com>
 
 
 - Manipulating list