Endorsement of list comprehensions

Skip Montanaro skip at pobox.com
Fri May 2 15:25:45 EDT 2003


    def qsort2(lst):
        if len(lst) == 0:
            return []
        else:
            x = lst[0]
            return (qsort2([i for i in lst[1:] if i<x]) +
                    [x] +
                    qsort2([i for i in lst[1:] if i>=x])

I know this will probably sound odd, but for me, the first time I saw the
list comprehension expression of quicksort was the first time it was
immediately apparent to me how quicksort worked.

Skip





More information about the Python-list mailing list