Kay Schluehr <[EMAIL PROTECTED]> writes:

> On 9 Nov., 07:06, Steven D'Aprano <[EMAIL PROTECTED]
[...]
>> In any case, the above doesn't work now, since either L1 or L2 might
>> contain complex numbers.
>> The sorted() trick only works because you're
>> making an assumption about the kinds of things in the lists. If you want
>> to be completely general, the above solution isn't guaranteed to work.
>
> You are right. I never used complex numbers in Python so problems were
> not visible. Otherwise the following comp function in Python 2.X does
> the job:
>
> def comp(x1, x2):
>    try:
>        if x1<x2:
>            return -1
>        else:
>            return 1
>    except TypeError:
>        if str(x1)<str(x2):
>            return -1
>        else:
>            return 1
>

Sadly it fails on transitivity:

>>> comp(2, 3j)
-1
>>> comp(3j, True)
-1
>>> comp(True, 2)
-1

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

Reply via email to