Sorting a list with entries of unequal types
Paul Rubin
no.email at nospam.invalid
Thu Jan 28 19:32:49 EST 2010
Ben Finney <ben+python at benfinney.id.au> 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