5 ms·
The first section is pointing out list comprehensions as a better syntax than lambda, I believe. Also, the zen of python has been around for a long time: http:/
by TheBoff 16y ago
The first section is pointing out list comprehensions as a better syntax than lambda, I believe. Also, the zen of python has been around for a long time: http://www.python.org/dev/peps/pep-0020/ http://www.python.org/dev/peps/pep-0020/.
There's an import statement that will print it I believe, but I'm not sure exactly what it is.
- ronnix 16y ago$ python -c "import this"
- KirinDave 16y agoIt's a better syntax than Python's 10-year-out-of-date notion of lambda. For example, this is what a more modern language does with lambdas: numbers.filter( _ % 2 == 0 ) This document is old, so we can probably excuse it... but how many Python folks know that?
- d0mine 16y agoWhat is the language? numbers.filter( _ % 2 == 0 ).map( _ / 2 ) Zen of Python doesn't contain any lambdas (the link from the grandparent http://www.python.org/dev/peps/pep-0020/ http://www.python.org/dev/peps/pep-0020/ ). List Comprehensions are 10 years old http://www.python.org/dev/peps/pep-0202/ http://www.python.org/dev/peps/pep-0202/ How do you write: lambda x, y=1: x+y lambda *args: reduce(lcm, args) lambda **kwargs: kwargs.get('a') or kwargs.get('b') def lcm(a, b): return a*b // gcd(a, b) def gcd(a, b): while b: a, b = b, a % b return a
- KirinDave 16y agoThe link for the thread: http://artifex.org/~hblanks/talks/2011/pep20_by_example.py.txt http://artifex.org/~hblanks/talks/2011/pep20_by_example.py.t... It does indeed mention a lambda in the very first example, if only as a competition with list comprehension syntax. But even Python's list comprehensions look a little dated now.
- eru 16y agoPython's list comprehension is actually inspired by Haskell (or was it the other way around)? What do you mean by dated? What new ideas have come up for List comprehension syntax? (I agree that Lambda should be call fun or fn or \. An implicit _ might also work, though that's somewhat against Python's spirit---c.f. the explicit self in methods.)
- sausagefeet 16y agoLike most good ideas, it came from Haskell :) The part that bothers me about the list comprehension section is that conflating list comprehension and lambda. Is it telling me that list comprehension is better than map/filter or better than lambda? I don't know. Quiet honestly, in many situations I find: halves_evens = lambda nums : [i/2 for i in nums if nums % 2 == 0] to be the cleanest.
- runT1ME 16y agoscala.