3
$\begingroup$

I have two lists xx and yy where

aa = {1, 2, 3, 4}; 
bb = {12, 13, 14, 15}; 
cc = {23, 24, 25, 26}; 
dd = {34, 35, 36, 37};
xx = {aa, bb, cc, dd}; 
yy = Transpose[xx];

After Transpose,

xx = {{1, 2, 3, 4}, {12, 13, 14, 15}, {23, 24, 25, 26}, {34, 35, 36, 37}}
yy = {{1, 12, 23, 34}, {2, 13, 24, 35}, {3, 14, 25, 36}, {4, 15, 26, 37}}

The goal is to execute a function, Print for example, over these two lists by taking from each list one sublist at a time

zz = Map[Print[#1, #2] &, {xx, yy}];

The object is to get print-out a pair at a time: {{1, 2, 3, 4}, {1, 12, 23, 34}}, then {{12, 13, 14, 15}, {2, 1, 3, 24, 35}}, so on...

$\endgroup$

2 Answers 2

4
$\begingroup$
 MapThread[Print[#1, #2] &, {xx, yy}];

Mathematica graphics

$\endgroup$
4
$\begingroup$

You can Transpose the list {xx, yy} and Apply your function at Level 1:

foo @@@ Transpose[{xx, yy}]
{foo[{1, 2, 3, 4}, {1, 12, 23, 34}], 
 foo[{12, 13, 14, 15}, {2, 13, 24, 35}], 
 foo[{23, 24, 25, 26}, {3, 14, 25, 36}], 
 foo[{34, 35, 36, 37}, {4, 15, 26, 37}]}
Print @@@ Transpose[{xx, yy}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.