One line sort
Chris Angelico
rosuav at gmail.com
Mon Nov 15 14:03:13 EST 2021
On Tue, Nov 16, 2021 at 5:58 AM ast <ast at invalid> wrote:
>
> A curiosity:
>
> q = lambda x: x and q([i for i in x[1:] if i < x[0]]) + [x[0]] + q([i
> for i in x[1:] if i >= x[0]])
>
> >>> q([7, 5, 9, 0])
> [0, 5, 7, 9]
A nicely obfuscated quicksort. Although the "one line" part falls down
a bit if it has to get wrapped for the mailing list post.
(Horribly inefficient, but it's clear what the intention is.)
ChrisA
More information about the Python-list
mailing list