Python 3.0 - is this true?

"Martin v. Löwis" martin at v.loewis.de
Sun Nov 9 13:18:02 EST 2008


> Sure:
> 
> if len(L1) == len(L2):
>     return sorted(L1) == sorted(L2)  # check whether two lists contain
> the same elements
> else:
>     return False
> 
> It doesn't really matter here what the result of the sorts actually is
> as long as the algorithm leads to the same result for all permutations
> on L1 ( and L2 ).

Unfortunately, for many releases, the list's sort algorithm would not
provide that property. Release for release, new cases where found where
the builtin ordering was not transitive (i.e. you get a < b and b < c,
but not a < c). With funny definitions of __cmp__ in some classes, you
can still get this today.

Regards,
Martin



More information about the Python-list mailing list