Comparisons of incompatible types
Ben Finney
ben+python at benfinney.id.au
Tue Dec 7 19:58:03 EST 2010
Carl Banks <pavlovevidence at gmail.com> writes:
> On Dec 6, 4:17 pm, Steven D'Aprano <steve
> +comp.lang.pyt... at pearwood.info> wrote:
> > Nevertheless, I agree that in hindsight, the ability to sort such
> > lists is not as important as the consistency of comparisons.
>
> I think that feeling the need to sort non-homogenous lists is
> indictative of bad design.
It can also be indicative of code written for a Python that doesn't have
sets.
Comparing two list objects to see whether they have the same items in
any sequence can be done with::
set(foolist) == set(barlist)
but, if there is no ‘set’ type, it's fine to write::
sorted(foolist) == sorted(barlist)
So there's no design error in wanting heterogenerous sequences to sort;
it can be quite Pythonic (until the advent of the ‘set’ type).
And, of course, that code needs to continue to work in Python 2.x;
hence, the comparison of incompatible types cannot be fixed without
breaking backward compatibility. Hence it's not fixed until Python 3.x.
--
\ “All opinions are not equal. Some are a very great deal more |
`\ robust, sophisticated and well supported in logic and argument |
_o__) than others.” —Douglas Adams |
Ben Finney
More information about the Python-list
mailing list