# How to apply # on different lists? [duplicate]

If I have

list1 = {1, 2, 3, 4}
list2 = {5, 6, 7, 8}


How can I do so, that

function[#1, #2]


takes #1 from list1 and #2 from list2??

• Duplicates: (10211), (15556) Commented Jan 18, 2015 at 15:26

MapThread[function[#1, #2] &, {list1, list2}]

• No need for: [#1, #2] &
– Kuba
Commented Jan 18, 2015 at 14:36
• @David No, that's not the same, unless function happens to be listable. Commented Jan 18, 2015 at 19:39

Since your question leaves a wide range of possible interpretations I suggest to examine these methods

Inner[ f, list1, list2, List]

{f[1, 5], f[2, 6], f[3, 7], f[4, 8]}


or

f @@@ Transpose[{list1, list2}]


or

Thread[ f[ Transpose[{list1, list2}]]]


Perhaps you could prefer Outer providing all possible pairs

 Outer[ f, list1, list2]

{{f[1, 5], f[1, 6], f[1, 7], f[1, 8]},
{f[2, 5], f[2, 6], f[2, 7], 2, 8]},
{f[3, 5], f[3, 6], f[3, 7], f[3, 8]},
{f[4, 5], f[4, 6], f[4, 7], f[4, 8]}}


or

f @@@ Tuples[{list1, list2}]

{ f[1, 5], f[1, 6], f[1, 7], f[1, 8], f[2, 5], f[2, 6],
f[2, 7], f[2, 8], 3, 5], f[3, 6], f[3, 7], f[3, 8],
f[4, 5], f[4, 6], f[4, 7], f[4, 8]}