How to do multiple arguments to map function where one remains the same in python?
Question: Lets 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 the 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.


Answer: One option is a list comprehension:

    
    
    [add(x, 2) for x in [1, 2, 3]]
    

More options:

    
    
    a = [1, 2, 3]
    
    import functools
    map(functools.partial(add, y=2), a)
    
    import itertools
    map(add, a, itertools.repeat(2, len(a)))
    

