Comparisons of incompatible types
Carl Banks
pavlovevidence at gmail.com
Tue Dec 7 18:20:01 EST 2010
On Dec 6, 4:17 pm, Steven D'Aprano <steve
+comp.lang.pyt... at pearwood.info> wrote:
> On Mon, 06 Dec 2010 08:59:12 -0800, TomF wrote:
> > I'm aggravated by this behavior in python:
>
> > x = "4"
> > print x < 7 # prints False
> > I can't imagine why this design decision was made.
>
> You've never needed to deal with an heterogeneous list?
>
> data = ["Fred", "Barney", 2, 1, None]
> data.sort()
Not once, ever.
> 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.
If the order of the items doesn't matter, then there must be some
small bit of homogeneity to exploit to use as a sort criterion. In
that case you should use key= parameter or DSU.
Carl Banks
More information about the Python-list
mailing list