# python - Black lambda Magic

In scipy.splev I found this piece of code:

``def splev( x, tck, int der=0, int ext=0):t,c,k = tcktry:c[0][0]parametric = Trueexcept:parametric = Falseif parametric:return list(map(lambda c, x=x, t=t, k=k, der=der: splev(x, [t,c,k], der, ext), c ))else:...return y.reshape(shape)``

and I fail to understand the lambda, please enlighten me.

The lambda function here:

``````lambda c, x=x, t=t, k=k, der=der: splev(x, [t,c,k], der, ext)
``````

is the same as:

``````def anonymous_lambda_function(c, x=x, t=t, k=k, der=der):
return splev(x, [t,c,k], der, ext)
``````

and map is mapping this function to the elements of an iterable, `c`.

The `list(map(...))` is redundant in Python 2, but it's necessary in Python 3, so it preserves the code's forward compatibility.

`lambdas` are just unnamed functions. You could write it like this:

``````def splev( x, tck, int der=0, int ext=0):

t,c,k = tck

def otherfxn(c, x=x, t=t, k=k, der=der):
return splev(x, [t,c,k], der, ext)

try:
c[0][0]
parametric = True
except:
parametric = False
if parametric:
return list(map(otherfxn, c))
else:
.
.
.
return y.reshape(shape)
``````