Let’s say we have a function add as follows

def add(x, y):
    return x + y

we want to apply map function for an array

map(add, [1, 2, 3], 2)

The semantics are I want to add 2 to every element of the array. But the map function requires a list in the third argument as well.

Note: I am putting the add example for simplicity. My original function is much more complicated. And of course option of setting the default value of y in add function is out of question as it will be changed for every call.

15 Answers
15

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *