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]])
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]])
- 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]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.