MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/Python/comments/9jfko6/stop_writing_lambda_expressions_in_python/e6r8845/?context=3
r/Python • u/treyhunner Python Morsels • Sep 27 '18
26 comments sorted by
View all comments
6
Tuple unpacking can improve readability over using hard-coded index lookups. Using lambda expressions often means sacrificing some Python language features, specifically those that require multiple lines of code (like an extra assignment statement).
Rebuttal: points_by_color = sorted(points, key=lambda ((x, y), color): color)
points_by_color = sorted(points, key=lambda ((x, y), color): color)
Overall agree though.
Edit: Looks like tuple parameter unpacking was removed in Python 3. https://www.python.org/dev/peps/pep-3113/ (I'm still using 2.7 for work, so that's my default.)
1 u/Sporke Sep 27 '18 I was hoping the author would mention operator.itemgetter(1) in that case
1
I was hoping the author would mention operator.itemgetter(1) in that case
operator.itemgetter(1)
6
u/rcfox Sep 27 '18 edited Sep 27 '18
Rebuttal:
points_by_color = sorted(points, key=lambda ((x, y), color): color)Overall agree though.
Edit: Looks like tuple parameter unpacking was removed in Python 3. https://www.python.org/dev/peps/pep-3113/ (I'm still using 2.7 for work, so that's my default.)