3 ms·
> List comprehensions and generator expressions have replaced all need for map, filter, and lambdas, and are far more readable. I would say that is debatable.
by psibi 11y ago
> List comprehensions and generator expressions have replaced all need for map, filter, and lambdas, and are far more readable.
I would say that is debatable. Coming from an FP background, I use map, filter and lambdas nearly all of the time because I find it more readable and can easily reason about the code. I have seen some two line list comprehensions and they are far harder for me to read and understand.
- aaronchall 11y agoOK so let's talk about that, which is more readable?: iterable = xrange(10) ge = (x*x for x in iterable if not x % 2) mf = map(lambda x: x*x, filter(lambda x: not x % 2, iterable)) Assume imap and ifilter from itertools or Python 3 (with range) for equivalence. I'm betting if we ask any person new to Python and new to programming, they'd think the former much more readable than the latter. Yes, we left it in the language for you cranks who think map, filter, and lambda are way better, but it's functionally no different.