Sorting a list with entries of unequal types

Paul Rubin at nospam.invalid
Fri Jan 29 01:32:49 CET 2010

Ben Finney <ben+python at> writes:
> So how should I be sorting a list with entries of “unequal types” such
> that it will work in Python 3?

Um, what ordering do you want?  Basically you have to write a custom key
function (they removed the option of writing a comparison function).

Maybe something like

    foo.sort(key=lambda x: (type(x), x))

would be enough to fool the sorting function?  I don't have python 3
so I haven't tried it.

More information about the Python-list mailing list