Ben Finney wrote:

> Peter Otten <__pete...@web.de> writes:
> 
>> I can't find the relevant part of the 2.6 documentation, but something
>> like
>>
>> >>> def key(x):
>> ...     t = type(x)
>> ...     t = compat.get(t, t)
>> ...     return t.__name__, id(t), x
>> ...
>> >>> compat = {bool: float, int: float}
> 
> The problem with this approach is that it assumes I know all the types
> of elements that will be sorted; I don't. I want to sort a list coming
> from some other part of the code, and I don't want to arbitrarily limit
> the types of the list elements.

I don't see the limitation here. The above key functions sorts unknown types 
by name, then id(type) then instance.

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

Reply via email to