a question regarding conciseness

Gerson Kurz gerson.kurz at t-online.de
Wed Feb 20 21:17:57 CET 2002


On Wed, 20 Feb 2002 21:48:52 +0100, Christophe Delord
<christophe.delord at free.fr> wrote:

>Writting a function to sort lists may not be efficient :
>
>def my_sort(L):
>     L2 = L[:]
>     L2.sort()
>     return L2
>
>X = [...]
>for x in my_sort(X):
>     ....

Of course, you can always use quicksort:

q=lambda x,o=filter,r=lambda o:(lambda x=list(o)+[0],\
y=len(o)-1:(lambda:map(lambda i,s=x.__setitem__:s(-1,\
x[i])or s(i,x[y-i])or s(y-i,x[-1]),range((y+1)/2))and\
0)() or (lambda:"".join(x[:-1]))())(),s=')]1=<)x(nel'\
'[]"x",))"o(lambda i,j=x[0]:i"(r,"~"(ecalper.)"q(~<j'\
',x))+~==j,x)+q(~>j,x))"(r[(lave':eval(r(s))

import random
test = range(20)
random.shuffle(test)
print test, "->", q(test)




More information about the Python-list mailing list