3 ms·
The first two situations where he recommends avoiding lambda I would agree with. But when he assigns `colors_by_length`, that's a perfectly valid usage of lambd
by sephware 8y ago
The first two situations where he recommends avoiding lambda I would agree with. But when he assigns `colors_by_length`, that's a perfectly valid usage of lambda. It's actually an ideal example of why it exists. His `length_and_alphabetical` is not an improvement. The tuple unpacking is something that destructuring in lambda syntax would improve, as it did with JavaScript. In ES6 it would be:
const points = [[[1, 2], 'red'], [[3, 4], 'green']]
const points_by_color = points
.sort(([point, color]) => color)
I know it's kind of futile to argue against a point using what-ifs, but personally I wish Python embraced this style of functional programming a little bit more and adapted its syntax to it, rather than coming across articles where people recommend against this style just because the language isn't (currently) as suitable to it.
- rcfox 8y agoPython 2.7 had tuple parameter unpacking, but it was removed in Python 3. https://www.python.org/dev/peps/pep-3113/ https://www.python.org/dev/peps/pep-3113/