Need a strange sort method...

Paul Rubin http
Mon Oct 16 20:28:07 CEST 2006


"SpreadTooThin" <bjobrien62 at gmail.com> writes:
> a = [1,2,3,4,5,6,7,8,9,10] #Although not necessarily in order
> 
> def cmp(i,j):  #to be defined in this thread.
> 
> a.sort(cmp)
> 
> print a
> [1,4,7,10,  2,5,8, 3,6,9]

def k(n): return (n-1) % 3, (n-1) // 3
a.sort(key=k)



More information about the Python-list mailing list