this customize sort did not work ,what's wrong?
Duncan Booth
duncan.booth at invalid.invalid
Sat Jan 23 16:40:29 EST 2010
thinke365 <thinke365 at gmail.com> wrote:
> jesus, now i fixed it, using odd lambda sort.
> l.sort(lambda x,y: cmp(len(x), len(y)))
> print l
>
> BUT I AM STILL CONFUSED WHY COSTOMIZED SORT FAILED TO SORT AS IT IS
> PROGRAMMER!
Try reading the documentation:
>>> help(list.sort)
Help on method_descriptor:
sort(...)
L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*;
cmp(x, y) -> -1, 0, 1
Your comparison function returned True or False, not -1, 0, +1
More information about the Python-list
mailing list