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).
Looks like tuple parameter unpacking was removed in Python 3
I am still a bit salty about this in the context of lambdas. indexing into tuples as opposed to unpacking is bullshit and the supposedly more elegant itemgetter whatever is bullshit too.
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.)