5 ms·
Here is a fun one-liner quicksort in Python: def q(list): return [] if list==[] else q([x for x in list[1:] if x < list[0]]) + [list[0]] + q([x for x in list[
by wooptoo 9y ago
Here is a fun one-liner quicksort in Python:
def q(list): return [] if list==[] else q([x for x in list[1:] if x < list[0]]) + [list[0]] + q([x for x in list[1:] if x >= list[0]])
- rantanplan 9y agoHate to be that guy and I know it's just for fun, but that is not a one-liner. Not at a 135-characters length :) And I'm not even accounting for the 1-char useless var/func names. EDIT: To clarify, I don't think that the above "1 liner" has anything to offer. 1) It's not pythonic, 2) it's not 1-liner by any of python's standards and 3) it's a bad example of programming. While on the other hand there are numerous other 1-liners that do not have these bad traits.
- heavenlyblue 9y agoNeither is it fun, readable or implies any sorts of knowledge of the language. - One-char function names. - You call a "list" a list. Shadows built-ins. At least use lst. - if list==[] is non PEP8. Should be if not list. - [list[0]] could be written as list[:1]