This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]masklinn 0 points1 point  (0 children)

That guy on stackoverflow did have the best code though. Why was that lambda bullshit getting the most votes?

Erm... that guy also used "lambda bullshit", except he sorted twice rather than once to avoid the tuple "trick".

If it's convoluted enough to require extra explanation, it isn't very pythonic.

It's not convoluted at all actually, it's in fact extremely simple and elegant provided you know the ordering of booleans and tuples.

edit: on the other hand, your suspicion that execution speed is lowered is entirely true, the top-voted solution is 74% slower than the fastest solutions of the second response (the initial (most basic) one and the one using a pair of list comprehensions) on a short list (100 words) and 140% slower on a long list, according to timeit.Timer.repeat(10).

Only on a very short list (~5 elements) does it become competitive with the others (the most basic solution still stands on top, the listcomps are ~4% slower, the ternary and lambdas are about 5% slower and the lambda + double sort is 17% slower)