On Sat, Jan 23, 2010 at 12:57 PM, thinke365 <thinke...@gmail.com> wrote:

> def sort_by_list(E1, E2):
>    print len(E1), len(E2)
>    return len(list(E1)) > len(list(E2))
>
> l.sort(cmp=sort_by_list)
>

The cmp function is defined as returning one of three values, -1, 0 and 1.

You are returning true or false, so things aren't getting sorted because
you're not giving cmp what it is looking for. You could rewrite that as
return cmp(len(list(E1)), len(list(E2))) if you want. However, cmp is going
away in Py3.

You can just do, instead:

l.sort(key=len)

And you'll get precisely what you're looking for.

--S
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to