list comprehensions *are* nice

Nathan Gray n8gray at
Tue May 15 00:50:50 EDT 2001

Andrew Dalke wrote in message <9doc1h$3sp$1 at>...
>A couple months ago I complained that list comprehensions were
>too confusing and that I would still be using
>   results = []
>   for val in data:
>     results.append(..some.expression.using.val..)
>I was wrong.

def qsort(lst):
    if len(lst) <= 1: return lst
    return qsort([lessthan for lessthan in lst[1:] if lessthan < lst[0]]) +
            [lst[0]] + qsort([grtreq for grtreq in lst[1:] if grtreq >=

Take that, Haskell!  List comprehensions are rad.


More information about the Python-list mailing list