a question regarding conciseness

Christophe Delord christophe.delord at free.fr
Thu Feb 21 13:37:30 EST 2002


The problem with sort is that it sorts the list as a side effect.

I found other solutions (but not as short as yours :-)

q=lambda L,c=cmp:(lambda f=lambda s:filter(lambda i:c(i,L[0])==s,L):L 
and q(f(-1))+f(0)+q(f(1)))()

or without filter:

q=lambda L,c=cmp:(lambda f=lambda s:[i for i in L if c(i,L[0])==s]:L and 
q(f(-1))+f(0)+q(f(1)))()

or

q=lambda L,c=cmp:L and(lambda m=[],e=[],M=[]:map(lambda 
x:{-1:m,0:e,1:M}[c(x,L[0])].append(x),L)and q(m)+e+q(M))()



Christophe.


Gerson Kurz wrote:

> I found an easier solution:
> 
> sort = lambda x:(x.sort(),x)[1]
> 
> 

--
Christophe Delord
http://christophe.delord.free.fr




More information about the Python-list mailing list