Q: sort's key and cmp parameters
Laszlo Nagy
gandalf at shopzeus.com
Thu Oct 1 13:51:14 EDT 2009
Is this a homework?
> Challenge: to come up with a sorting task that cannot be achieved
> by passing to the sort method (or sorted function) suitable values
> for its key and reverse parameters, but instead *require* giving
> a value to its cmp parameter.
>
Let me put up this question: how do you define the difference between an
object to be sorted in the list, and the passed "suitable value" that is
used for finding the position for the object in the list. If the only
difference is that they need to be different Python objects, then you
can always use [x] instead of x. This value is perfectly suitable. ;-)
If you could give us somewhat stronger requirements regarding keys and
objects, we may give you a different answer.
Best,
Laszlo
More information about the Python-list
mailing list