I'm a huge fan of the lambda syntax :
x -> x * 2
It looks much cleaner than the traditional :
lambda x : x * 2
Would a PEP adding this syntax have any chance to pass ?
x -> x * 2
It looks much cleaner than the traditional :
lambda x : x * 2
Would a PEP adding this syntax have any chance to pass ?
So where in javascript you would write:
const double = x => x * 2
In python you can simply write: from operator import mul
double = mul(2)
[1]: https://docs.python.org/2/library/operator.html from functools import partial
import operator
double = partial(operator.mul, 2)
And at that point I think it would way simpler to just define a normal function. def double(x): return x * 2
Python's `lambda` construct creates anonymous functions - its limitations mean it should only be used when anonymity is required. If a function is to be given a name, there is no reason to use a lambda over standard function syntax.I'm a big fan of the way Haskell manages operators and partial application.
double :: Num a => a -> a
double = (2 *)foo = a -> b -> a+2*b
It's pretty lispy language.
Python wants to be broadly good enough for everyone, not perfect for any one person's specific domain and expertise level. I think this might be the right attitude.