Re: Comparison of functions

2005-08-01 Thread Steven Bethard
Steven D'Aprano wrote: You are confusing mathematical ordering with sorting a list. Here, I will sort some mixed complex and real numbers for you. If you look at them closely, you will even be able to work out the algorithm I used to sort them. 1 1+0j 1+7j 2 2+3j 3+3j 3-3j 3+4j 4

Re: Comparison of functions

2005-07-31 Thread Rocco Moretti
Adriano Varoli Piazza wrote: As far as I recall from Math Analysis, which I studied two months ago, you can't sort complex numbers. It makes no sense. The reason being (reading from my book), it's not possible to define an order that preserves the properties of arithmetical operations on

Re: Comparison of functions

2005-07-31 Thread Dan Bishop
Steven D'Aprano wrote: On Sat, 30 Jul 2005 16:43:00 +, Adriano Varoli Piazza wrote: If you want to treat numbers as strings, why not convert them before sorting them? Because that changes the object and throws away information. I think he meant doing something like - lst = ['2+2j',

Comparison of functions

2005-07-30 Thread Steven D'Aprano
Playing around with comparisons of functions (don't ask), I discovered an interesting bit of unintuitive behaviour: (lambda y: y) (lambda y: y) False Do the comparison again and things become even more bizarre: (lambda y: y) (lambda y: y) True (lambda y: y) (lambda y: y) False This

Re: Comparison of functions

2005-07-30 Thread Peter Hansen
Steven D'Aprano wrote: Playing around with comparisons of functions (don't ask), I discovered an interesting bit of unintuitive behaviour: (lambda y: y) (lambda y: y) False Do the comparison again and things become even more bizarre: (lambda y: y) (lambda y: y) True (lambda y: y)

Re: Comparison of functions

2005-07-30 Thread tiissa
Steven D'Aprano wrote: Playing around with comparisons of functions (don't ask), I discovered an interesting bit of unintuitive behaviour: a = lambda y: y b = lambda y: y a function lambda at 0xf70598ec b function lambda at 0xf7059844 a b False So I'm puzzled about how Python compares

Re: Comparison of functions

2005-07-30 Thread Steven D'Aprano
On Sat, 30 Jul 2005 08:13:26 -0400, Peter Hansen wrote: Beginners should not be comparing lambdas. Neither should you. ;-) Actually, yes I should, because I'm trying to make sense of the mess that is Python's handling of comparisons. At least two difference senses of comparisons is jammed

Re: Comparison of functions

2005-07-30 Thread Steven D'Aprano
On Sat, 30 Jul 2005 14:20:50 +0200, tiissa wrote: Steven D'Aprano wrote: Playing around with comparisons of functions (don't ask), I discovered an interesting bit of unintuitive behaviour: a = lambda y: y b = lambda y: y a function lambda at 0xf70598ec b function lambda at 0xf7059844 a b

Re: Comparison of functions

2005-07-30 Thread Adriano Varoli Piazza
Steven D'Aprano ha scritto: On Sat, 30 Jul 2005 08:13:26 -0400, Peter Hansen wrote: Beginners should not be comparing lambdas. Neither should you. ;-) Actually, yes I should, because I'm trying to make sense of the mess that is Python's handling of comparisons. At least two difference

Re: Comparison of functions

2005-07-30 Thread Adriano Varoli Piazza
Adriano Varoli Piazza ha scritto: As far as I recall from Math Analysis, which I studied two months ago, you can't sort complex numbers. It makes no sense. The reason being (reading from my book), it's not possible to define an order that preserves the properties of arithmetical operations

Re: Comparison of functions

2005-07-30 Thread Reinhold Birkenfeld
Steven D'Aprano wrote: On Sat, 30 Jul 2005 08:13:26 -0400, Peter Hansen wrote: Beginners should not be comparing lambdas. Neither should you. ;-) Actually, yes I should, because I'm trying to make sense of the mess that is Python's handling of comparisons. At least two difference senses

Re: Comparison of functions

2005-07-30 Thread Georg Neis
* Reinhold Birkenfeld [EMAIL PROTECTED] wrote: Steven D'Aprano wrote: 1+0j == 1 0 True (1+0j == 1) yields True, which is comparable to 0. a == b c is equivalent to a == b and b c: 1 == 1+0j 0 Traceback (most recent call last): File stdin, line 1, in ? TypeError: cannot compare

Re: Comparison of functions

2005-07-30 Thread Steven D'Aprano
On Sat, 30 Jul 2005 13:22:47 +, Adriano Varoli Piazza wrote: As far as I recall from Math Analysis, which I studied two months ago, you can't sort complex numbers. It makes no sense. The reason being (reading from my book), it's not possible to define an order that preserves the

Re: Comparison of functions

2005-07-30 Thread Steven D'Aprano
On Sat, 30 Jul 2005 13:30:20 +, Adriano Varoli Piazza wrote: But tell me, how do you think sort works if not with , , ==, = and = ? I'm really interested. How do you sort words in a dictionary? Why does five come before four when the number five is larger than the number four? Why does

Re: Comparison of functions

2005-07-30 Thread Adriano Varoli Piazza
Steven D'Aprano ha scritto: It was easy. I never once asked myself whether some complex number was greater or less than another, I just asked which one comes first in a lexicographic sort? The two questions are NOT the same, and it is an ugliness in an otherwise beautiful language that

Re: Comparison of functions

2005-07-30 Thread Adriano Varoli Piazza
Steven D'Aprano ha scritto: On Sat, 30 Jul 2005 13:30:20 +, Adriano Varoli Piazza wrote: But tell me, how do you think sort works if not with , , ==, = and = ? I'm really interested. How do you sort words in a dictionary? Why does five come before four when the number five is

Re: Comparison of functions

2005-07-30 Thread Steven D'Aprano
On Sat, 30 Jul 2005 15:32:45 +0200, Reinhold Birkenfeld wrote: Um, I didn't ask to compare complex numbers using comparison operators. I asked to sort a list. And please don't tell me that that sorting is implemented with comparison operators. That just means that the implementation is

Re: Comparison of functions

2005-07-30 Thread Adriano Varoli Piazza
Steven D'Aprano ha scritto: On Sat, 30 Jul 2005 13:22:47 +, Adriano Varoli Piazza wrote: As far as I recall from Math Analysis, which I studied two months ago, you can't sort complex numbers. It makes no sense. The reason being (reading from my book), it's not possible to define an order

Re: Comparison of functions

2005-07-30 Thread Kay Schluehr
Some indications: for i in range(5): ... x = lambda x:x ... y = lambda y:y ... print x,y,xy,id(x)id(y) ... function lambda at 0x00EE83F0 function lambda at 0x00EE8FB0 True True function lambda at 0x00EE8AB0 function lambda at 0x00EE83F0 False False function lambda at 0x00EE8FB0

Re: Comparison of functions

2005-07-30 Thread tiissa
Steven D'Aprano wrote: It was easy. I never once asked myself whether some complex number was greater or less than another, I just asked which one comes first in a lexicographic sort? The two questions are NOT the same, and it is an ugliness in an otherwise beautiful language that Python

Re: Comparison of functions

2005-07-30 Thread Reinhold Birkenfeld
Georg Neis wrote: * Reinhold Birkenfeld [EMAIL PROTECTED] wrote: Steven D'Aprano wrote: 1+0j == 1 0 True (1+0j == 1) yields True, which is comparable to 0. a == b c is equivalent to a == b and b c: Right. Stupid me :) Doesn't do much to the point, though. 1 == 1+0j 0 Traceback

Re: Comparison of functions

2005-07-30 Thread Reinhold Birkenfeld
they are similar enough in some contexts as to cause confusion. Well, you can order everything according to some specs, but you can't find a default sort order for everything. That's where custom comparison functions can help. Correct me if I'm wrong, but is there a default order for complex number

Re: Comparison of functions

2005-07-30 Thread Steven D'Aprano
On Sat, 30 Jul 2005 16:13:22 +, Adriano Varoli Piazza wrote: Steven D'Aprano ha scritto: It was easy. I never once asked myself whether some complex number was greater or less than another, I just asked which one comes first in a lexicographic sort? The two questions are NOT the

Re: Comparison of functions

2005-07-30 Thread Adriano Varoli Piazza
Steven D'Aprano ha scritto: Do you understand the difference between partial and total ordering, or weakly and strongly ordered? When you do understand them, come back and tell me again whether you still think lexicographic sorting has no meaning whatsoever. I think I answered this in

Re: Comparison of functions

2005-07-30 Thread Steven D'Aprano
On Sat, 30 Jul 2005 16:43:00 +, Adriano Varoli Piazza wrote: If you want to treat numbers as strings, why not convert them before sorting them? Because that changes the object and throws away information. Here is a list, containing one complex number converted to a string, and one

Re: Comparison of functions

2005-07-30 Thread Steven D'Aprano
On Sat, 30 Jul 2005 17:57:20 +, Adriano Varoli Piazza wrote: Steven D'Aprano ha scritto: Do you understand the difference between partial and total ordering, or weakly and strongly ordered? When you do understand them, come back and tell me again whether you still think lexicographic

Re: Comparison of functions

2005-07-30 Thread Erik Max Francis
Steven D'Aprano wrote: Um, I didn't ask to compare complex numbers using comparison operators. I asked to sort a list. And please don't tell me that that sorting is implemented with comparison operators. That just means that the implementation is confusing numeric ordering with sort order.

Re: Comparison of functions

2005-07-30 Thread Peter Hansen
Steven D'Aprano wrote: Python already allows you to compare this is not a number with the float 5.0. Mathematically, that is meaningless, but I would bet money that 99.9% of programmers would demand that they should be able to sort the list [this is not a number, 5.0]. Do you think that it is

Re: Comparison of functions

2005-07-30 Thread Bengt Richter
On Sat, 30 Jul 2005 23:37:04 +1000, Steven D'Aprano [EMAIL PROTECTED] wrote: On Sat, 30 Jul 2005 14:20:50 +0200, tiissa wrote: Steven D'Aprano wrote: Playing around with comparisons of functions (don't ask), I discovered an interesting bit of unintuitive behaviour: a = lambda y: y b =