comparison on list yields surprising result

  • Thread starter Dr. Phillip M. Feldman
  • Start date
D

Dr. Phillip M. Feldman

In [21]: x
Out[21]: [1, 2, 3, 5]

In [22]: x>6
Out[22]: True

Is this a bug?
 
D

Diez B. Roggisch

Dr. Phillip M. Feldman said:
In [21]: x
Out[21]: [1, 2, 3, 5]

In [22]: x>6
Out[22]: True

Is this a bug?

In python2.x, it's the defined behavior - all types are somhow
comparable. The comparison is stable (all lists compare larger to all
ints), but of course this by no means well-defined.

This debatable design-decision has been remedied in Python3:

Python 3.1 (r31:73578, Jun 27 2009, 21:49:46)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):





Diez
 
D

Diez B. Roggisch

Dr. Phillip M. Feldman said:
In [21]: x
Out[21]: [1, 2, 3, 5]

In [22]: x>6
Out[22]: True

Is this a bug?

In python2.x, it's the defined behavior - all types are somhow
comparable. The comparison is stable (all lists compare larger to all
ints), but of course this by no means well-defined.

This debatable design-decision has been remedied in Python3:

Python 3.1 (r31:73578, Jun 27 2009, 21:49:46)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):





Diez
 
D

Dr. Phillip M. Feldman

It looks as though what I should have done is the following:

In [23]: array(x) > 6
Out[23]: array([False, False, False, False], dtype=bool)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,125
Latest member
VinayKumar Nevatia_
Top