In python, functions are first-class citizens, just like in javascript:
def adder(n):
def add_func(x):
return x + n
return add_func
add3 = adder(3)
print map(add3, [1,2,3]) # [4, 5, 6]
This is not the only option, for example adder
can also be written as:
def adder(n):
return lambda x: x + n
Note that functional style is not quite pythonic, when possible, we prefer comprehensions and generators over high-order functions:
wrapped = ["<p>{}</p>".format(name) for name in names]