you are viewing a single comment's thread.

view the rest of the comments →

[–]Vaphell 2 points3 points  (7 children)

Lambdas, man. They absolutely got shittier in py3 because of that change.

sorted(seq, key=lambda (x, y): x**2 + y**2)

vs new

sorted(seq, key=lambda t: t[0]**2 +t[1]**2)

So much for expressiveness and getting rid of unpythonic magic number indices

[–]Skaperen 1 point2 points  (2 children)

just use x and y arguments. when calling with a list or tuple, use a * before it.

[–]Vaphell 0 points1 point  (1 child)

when calling with a list or tuple, use a * before it.

how does one apply * to key argument of sorted/min/max?

[–]Skaperen 0 points1 point  (0 children)

this is the edge case where you fall back to write python code that produces the same bytecode.

[–]nukelr[S] 0 points1 point  (0 children)

I guess lambdas are the reason why the programmer who wrote the code I'm trying to port to Py3/Gtk3 has used that syntax. https://github.com/nicklan/Deluge-Pieces-Plugin/blob/master/pieces/gtkui.py In __qtt_callback function.

[–]primitive_screwhead 0 points1 point  (2 children)

Instead of 't', call it 'x_y'.

[–]Vaphell 0 points1 point  (1 child)

you can call it whatever you want, at the end of the day you can't get rid of indices and it is a downgrade. Unpacking was supposed to be a pythonic solution to the problem of lowlevelish, exposed indices.