# Mapping function onto two lists, simultaneously [duplicate]

I have this function

test=> Is just a list of lists of depth 4
list1={3,2,1,0}
list2={1,2,3,4}
lag[l_List, n_Integer] := Drop[PadLeft[l, Length[l] + n, "Blank"], -n]
lag[test[[1, #2]], #1]&/@list1/@list2


As you can see this does not work, I understand why it does not work, but I have not been able to come up with an solution. What I want to happen is described in the list below. Basically I want list1 to go into slot1 and list2 to go into slot2 stepwise as shown below.

lag[test[[1, 1]], 3]
lag[test[[1, 2]], 2]
lag[test[[1, 3]], 1]
lag[test[[1, 4]], 0]

• Have you read the documentation on MapThread?
– ssch
Sep 18 '13 at 11:45
• Yeah, Im struggling with the understanding how to assign different list to different slot Sep 18 '13 at 11:49
• Related: (5217), (10211), (24939) Sep 18 '13 at 22:08

Voting to close, but:

list1 = {3, 2, 1, 0};
list2 = {1, 2, 3, 4};
MapThread[lag[test[[1, #2]], #1] &, {list1, list2}]

• aaaa, thought I came up with a good solution by myself, but yours is better. Would I be correct to state that MapThread is the same as using Map[apply[ ---> as I have done? Sep 18 '13 at 12:29
• @ALEXANDER test this vb = Transpose[{list1, list2}]; Map[lag[test[[1, #[[2]]]], #[[1]]] &, vb]. In Mathematica you always have a lot of ways to do the same thing. Sep 18 '13 at 12:42
list1 = {3, 2, 1, 0};
list2 = {1, 2, 3, 4};
vb = Transpose[{list1, list2}]
Map[(Apply[lag[test[[1, #2]], #1] &, #1]) &, vb]