dictionary - Fixed parameter for Map() in python -


is there anyway user map on list 1 fixed parameter without loop? example

def addx(x, y):   return x + y  print map(addx, 10, [10,20]) 

output should 20 , 30

thanks

you can use lambda anonymous-function creator inline new function 1 argument:

python 2.7.10 (default, aug 22 2015, 20:33:39) [gcc 4.2.1 compatible apple llvm 7.0.0 (clang-700.0.59.1)] on darwin type "help", "copyright", "credits" or "license" more information. >>> def addx(x,y): ...     return x+y ... >>> map(lambda x: addx(x,10), [10, 20]) [20, 30] >>> 

Comments