Re: comparison on list yields surprising result

2009-08-29 Thread Hendrik van Rooyen
On Friday 28 August 2009 21:00:31 Dr. Phillip M. Feldman wrote:
 In [21]: x
 Out[21]: [1, 2, 3, 5]

 In [22]: x6
 Out[22]: True

 Is this a bug?

No, it is a feature, so that you can use sorted on this:

[[1,2,3,4,5],6]

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


Re: comparison on list yields surprising result

2009-08-29 Thread Steven D'Aprano
On Sat, 29 Aug 2009 09:36:38 +0200, Hendrik van Rooyen wrote:

 On Friday 28 August 2009 21:00:31 Dr. Phillip M. Feldman wrote:
 In [21]: x
 Out[21]: [1, 2, 3, 5]

 In [22]: x6
 Out[22]: True

 Is this a bug?
 
 No, it is a feature, so that you can use sorted on this:
 
 [[1,2,3,4,5],6]


If it's a feature, it has gone away in Python 3.


Python 3.0.1 (r301:69556, Apr  2 2009, 00:41:38)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2
Type help, copyright, credits or license for more information.
 [[1,2,3], 5].sort()
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: unorderable types: int()  list()




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


comparison on list yields surprising result

2009-08-28 Thread Dr. Phillip M. Feldman

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

In [22]: x6
Out[22]: True

Is this a bug?
-- 
View this message in context: 
http://www.nabble.com/comparison-on-list-yields-surprising-result-tp25195170p25195170.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: comparison on list yields surprising result

2009-08-28 Thread John Machin
On Aug 29, 5:00 am, Dr. Phillip M. Feldman pfeld...@verizon.net
wrote:
 In [21]: x
 Out[21]: [1, 2, 3, 5]

 In [22]: x6
 Out[22]: True

 Is this a bug?

No.

http://docs.python.org/reference/expressions.html#notin


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


Re: comparison on list yields surprising result

2009-08-28 Thread Diez B. Roggisch

Dr. Phillip M. Feldman schrieb:

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

In [22]: x6
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.
 list(range(10))  10
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: unorderable types: list()  int()






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


Re: comparison on list yields surprising result

2009-08-28 Thread Diez B. Roggisch

Dr. Phillip M. Feldman schrieb:

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

In [22]: x6
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.
 list(range(10))  10
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: unorderable types: list()  int()






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


Re: comparison on list yields surprising result

2009-08-28 Thread 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)
-- 
View this message in context: 
http://www.nabble.com/comparison-on-list-yields-surprising-result-tp25195170p25195893.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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