Q: sort's key and cmp parameters

Paul Rubin http
Thu Oct 1 14:41:22 EDT 2009


kj <no.email at please.post> writes:
> Is there a real-life sorting task that requires (or is far more
> efficient with) cmp and can't be easily achieved with key and
> reverse?

Yes, think of sorting tree structures where you have to recursively
compare them til you find an unequal pair of nodes.  To sort with
key=... you have to wrap a class instance around each tree, with
special comparison methods.  Blecch.



More information about the Python-list mailing list