Re: Python 3.0 - is this true?

2008-11-25 Thread Aahz
In article [EMAIL PROTECTED], Duncan Grisby [EMAIL PROTECTED] wrote: In article [EMAIL PROTECTED], Aahz [EMAIL PROTECTED] wrote: In article [EMAIL PROTECTED], Duncan Grisby [EMAIL PROTECTED] wrote: For my application, Python 3's comparison behaviour is a backwards step. You can argue all you

Re: Python 3.0 - is this true?

2008-11-25 Thread Steven D'Aprano
On Mon, 24 Nov 2008 17:33:50 +, Tim Rowe wrote: 2008/11/24 Aahz [EMAIL PROTECTED]: (I'll agree that from some perspectives the new behavior of None is a wart but I think that in the end I agree with people who say that preventing None from being sorted except intentionally will trap

Re: Python 3.0 - is this true?

2008-11-25 Thread Steven D'Aprano
On Mon, 24 Nov 2008 10:42:41 +, Duncan Grisby wrote: Again, this is just an example. As I say, in the real application, the data has come from a dynamically-typed database. There's no easy way to coerce all the items to the same type, because the application doesn't know up-front what the

Re: Python 3.0 - is this true?

2008-11-24 Thread Duncan Grisby
In article [EMAIL PROTECTED], Terry Reedy [EMAIL PROTECTED] wrote: [...] l = [] for line in open(bigfile.txt): x = random.randint(0,100) if x 4: l.append(None) else: l.append(line) So use '' or '\0' instead of None for null lines. Or replace None for the sort. Both '' and

Re: Python 3.0 - is this true?

2008-11-24 Thread Aahz
In article [EMAIL PROTECTED], Duncan Grisby [EMAIL PROTECTED] wrote: In article [EMAIL PROTECTED], Terry Reedy [EMAIL PROTECTED] wrote: Replace the sublists with a coded string, such as '\0'+line. Again, this is just an example. As I say, in the real application, the data has come from a

Re: Python 3.0 - is this true?

2008-11-24 Thread Tim Rowe
2008/11/24 Aahz [EMAIL PROTECTED]: (I'll agree that from some perspectives the new behavior of None is a wart but I think that in the end I agree with people who say that preventing None from being sorted except intentionally will trap more bugs earlier.) So will Python be introducing strong

Re: Python 3.0 - is this true?

2008-11-24 Thread Duncan Grisby
In article [EMAIL PROTECTED], Aahz [EMAIL PROTECTED] wrote: In article [EMAIL PROTECTED], Duncan Grisby [EMAIL PROTECTED] wrote: [...] That's exactly my point. Currently, the application just builds a list of values retrieved from the database and asks Python to sort it. No key or cmp function.

Re: Python 3.0 - is this true?

2008-11-24 Thread Martin v. Löwis
Sorry for the delay in replying. Thanks, and I'm in turn sorry myself, too. Here is my experiment: I only looked at the first test case, where a bigfile.txt has occasionally None lines. To run this test, I created a file with 33079296 and 704512 lines, by repeatedly cat'ing /etc/passwd. I

Re: Python 3.0 - is this true?

2008-11-19 Thread Duncan Grisby
In article [EMAIL PROTECTED], Martin v. Löwis [EMAIL PROTECTED] wrote: The sorting is in a performance-critical part of the system, so the overhead of evaluating a key function is not insignificant. Can you easily produce an example? It doesn't have to be real data, but should have the

Re: Python 3.0 - is this true?

2008-11-19 Thread Terry Reedy
Duncan Grisby wrote: Sorry for the delay in replying. Yes, that's not far off. Most of the time the lists contain strings, though. A better approximation might be to read lines from a file and randomly replace them with Nones: l = [] for line in open(bigfile.txt): x =

Re: Python 3.0 - is this true?

2008-11-11 Thread George Sakkis
On Nov 11, 8:02 am, M.-A. Lemburg [EMAIL PROTECTED] wrote: On 2008-11-11 02:10, Steven D'Aprano wrote: On Mon, 10 Nov 2008 12:51:51 +, Duncan Grisby wrote: I have an object database written in Python. It, like Python, is dynamically typed. It heavily relies on being able to sort lists

Re: Python 3.0 - is this true?

2008-11-11 Thread Robin Becker
M.-A. Lemburg wrote: On 2008-11-11 02:10, Steven D'Aprano wrote: On Mon, 10 Nov 2008 12:51:51 +, Duncan Grisby wrote: I have an object database written in Python. It, like Python, is dynamically typed. It heavily relies on being able to sort lists where some of the members are None. To

Re: Python 3.0 - is this true?

2008-11-11 Thread Terry Reedy
Duncan Grisby wrote: Yes, very hard. There is a difference between 'very hard' (to get 'right') and 'to slow' (for a particular application). I accept the latter. There are only ever simple types in the lists -- strings, integers, Nones, very occasionally floats, and lists of those

Re: Python 3.0 - is this true?

2008-11-11 Thread Terry Reedy
M.-A. Lemburg wrote: I think the special case for None should be readded to Python 3.0. Quick summary of thread that MAL started on Python-3000-dev list: Once upon a time, 0 None was true. When rich comparisons were added, None 0 (and *most* other things) become true as an intentionally

Re: Python 3.0 - is this true?

2008-11-11 Thread Martin v. Löwis
The sorting is in a performance-critical part of the system, so the overhead of evaluating a key function is not insignificant. Can you easily produce an example? It doesn't have to be real data, but should have the structure (typewise) of the real data. I would like to perform some

Re: Python 3.0 - is this true?

2008-11-11 Thread M.-A. Lemburg
On 2008-11-11 02:10, Steven D'Aprano wrote: On Mon, 10 Nov 2008 12:51:51 +, Duncan Grisby wrote: I have an object database written in Python. It, like Python, is dynamically typed. It heavily relies on being able to sort lists where some of the members are None. To some extent, it also

Re: Python 3.0 - is this true?

2008-11-11 Thread Robin Becker
Terry Reedy wrote: M.-A. Lemburg wrote: I think the special case for None should be readded to Python 3.0. Quick summary of thread that MAL started on Python-3000-dev list: Once upon a time, 0 None was true. When rich comparisons were added, None 0 (and *most* other things) become true

Re: Python 3.0 - is this true?

2008-11-11 Thread Duncan Grisby
In article [EMAIL PROTECTED], Terry Reedy [EMAIL PROTECTED] wrote: I have an object database written in Python. It, like Python, is dynamically typed. It heavily relies on being able to sort lists where some of the members are None. To some extent, it also sorts lists of other mixed types.

Null object pattern (was: Python 3.0 - is this true?)

2008-11-11 Thread Ben Finney
Terry Reedy [EMAIL PROTECTED] writes: We're not going to add the feature back that None compares smaller than everything. It's a slippery slope that ends with all operations involving None returning None -- I've seen a proposal made in all earnestness requesting that None+42 == None, None()

Re: Python 3.0 - is this true?

2008-11-10 Thread Aahz
In article [EMAIL PROTECTED], Roy Smith [EMAIL PROTECTED] wrote: The point is that you're forced to use lists to compute the sub-sequences. This makes sense, because lists fit the indefinite length sequence idea. Then, you're forced to use tuples as the dictionary keys, because tuples are

Re: Python 3.0 - is this true?

2008-11-10 Thread Terry Reedy
Duncan Grisby wrote: In article [EMAIL PROTECTED], Terry Reedy [EMAIL PROTECTED] wrote: Have you written any Python code where you really wanted the old, unpredictable behavior? I have an object database written in Python. It, like Python, is dynamically typed. It heavily relies on being

Re: Python 3.0 - is this true?

2008-11-10 Thread Robin Becker
Martin v. Löwis wrote: Sure: if len(L1) == len(L2): return sorted(L1) == sorted(L2) # check whether two lists contain the same elements else: return False It doesn't really matter here what the result of the sorts actually is as long as the algorithm leads to the same result for all

Re: Python 3.0 - is this true?

2008-11-10 Thread Duncan Grisby
In article [EMAIL PROTECTED], Terry Reedy [EMAIL PROTECTED] wrote: Have you written any Python code where you really wanted the old, unpredictable behavior? I have an object database written in Python. It, like Python, is dynamically typed. It heavily relies on being able to sort lists where

Re: Python 3.0 - is this true?

2008-11-10 Thread Steve Holden
Robin Becker wrote: Martin v. Löwis wrote: Sure: if len(L1) == len(L2): return sorted(L1) == sorted(L2) # check whether two lists contain the same elements else: return False It doesn't really matter here what the result of the sorts actually is as long as the algorithm leads

Re: Python 3.0 - is this true?

2008-11-10 Thread George Sakkis
On Nov 10, 4:10 am, Martin v. Löwis [EMAIL PROTECTED] wrote: Roy Smith wrote: Your choice of containers is not based on any theoretical arguments of what each type was intended to represent, but the cold hard reality of what operations they support. Right. What seems missing is a frozen

Re: Python 3.0 - is this true?

2008-11-10 Thread Robin Becker
Steve Holden wrote: .intain). Of course, using SQL against a traditional RDBMS will not return rows with NULL values for salary in a query such as SELECT name, address WHERE salary 1 precisely *because* NULL (absence of value) does not compare with any value. So you could say

Re: Python 3.0 - is this true?

2008-11-10 Thread Robin Becker
Robin Becker wrote: Steve Holden wrote: .intain). Of course, using SQL against a traditional RDBMS will not return rows with NULL values for salary in a query such as SELECT name, address WHERE salary 1 precisely *because* NULL (absence of value) does not compare with any

Re: Python 3.0 - is this true?

2008-11-10 Thread Steven D'Aprano
On Sun, 09 Nov 2008 10:45:31 -0500, Roy Smith wrote: As another example, consider a list of items being juggled: [RubberChicken(), ChainSaw(), Canteloupe()] I could go through contortions to find some common subclass for these items, but the whole *point* is that they're not of the same

Re: Python 3.0 - is this true?

2008-11-10 Thread Marc 'BlackJack' Rintsch
On Mon, 10 Nov 2008 16:32:47 +, Robin Becker wrote: on the other hand I find it odd that cmp(None,None) fails in Python 3 when None==None returns True. That's because there is no order defined for `NoneType` but equality is. Ciao, Marc 'BlackJack' Rintsch --

Re: Python 3.0 - is this true?

2008-11-10 Thread Martin v. Löwis
Roy Smith wrote: Your choice of containers is not based on any theoretical arguments of what each type was intended to represent, but the cold hard reality of what operations they support. Right. What seems missing is a frozen list type - the list needs to be frozen in order to be used as

Re: Python 3.0 - is this true?

2008-11-10 Thread rurpy
On Nov 10, 8:57 am, Steve Holden [EMAIL PROTECTED] wrote: Robin Becker wrote: ...snip... In old style python there was a sort of standard behaviour whereby None was comparable with most of the other primitive types. That at least allowed us to performs various stupid tricks with data.

Re: Python 3.0 - is this true?

2008-11-10 Thread Arnaud Delobelle
Robin Becker [EMAIL PROTECTED] writes: Steve Holden wrote: .intain). Of course, using SQL against a traditional RDBMS will not return rows with NULL values for salary in a query such as SELECT name, address WHERE salary 1 precisely *because* NULL (absence of value) does

Re: Python 3.0 - is this true?

2008-11-10 Thread George Sakkis
On Nov 10, 2:21 pm, [EMAIL PROTECTED] wrote: So you could say that 3.0 is forcing us to acknowledge database reality ;-) (Again) huh? Reality in databases is that NULL *is* comparable. NULL==something returns False, it doesn't raise an error. Given that in SQL NULL `op` something is

Re: Python 3.0 - is this true?

2008-11-10 Thread Rhamphoryncus
On Nov 10, 8:16 am, Terry Reedy [EMAIL PROTECTED] wrote: Duncan Grisby wrote: In article [EMAIL PROTECTED],  Terry Reedy  [EMAIL PROTECTED] wrote: Have you written any Python code where you really wanted the old, unpredictable behavior? I have an object database written in Python. It,

Re: Python 3.0 - is this true?

2008-11-10 Thread Steve Holden
[EMAIL PROTECTED] wrote: On Nov 10, 8:57 am, Steve Holden [EMAIL PROTECTED] wrote: Robin Becker wrote: ...snip... In old style python there was a sort of standard behaviour whereby None was comparable with most of the other primitive types. That at least allowed us to performs various stupid

Re: Python 3.0 - is this true?

2008-11-10 Thread Russ P.
On Nov 8, 10:20 am, walterbyrd [EMAIL PROTECTED] wrote: I have read that in Python 3.0, the following will raise an exception: [2, 1, 'A'].sort() Will that raise an exception? And, if so, why are they doing this? How is this helpful? Is this new enhancement Pythonic? I realize that I am

Re: Python 3.0 - is this true?

2008-11-10 Thread rurpy
On Nov 10, 1:21 pm, Steve Holden [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: On Nov 10, 8:57 am, Steve Holden [EMAIL PROTECTED] wrote: Robin Becker wrote: ...snip... In old style python there was a sort of standard behaviour whereby None was comparable with most of the other

Re: Python 3.0 - is this true?

2008-11-10 Thread rurpy
On Nov 10, 12:39 pm, George Sakkis [EMAIL PROTECTED] wrote: George Sakkis wrote: On Nov 10, 2:21 pm, [EMAIL PROTECTED] wrote: So you could say that 3.0 is forcing us to acknowledge database reality ;-) (Again) huh? Reality in databases is that NULL *is* comparable. NULL==something

Re: Python 3.0 - is this true?

2008-11-10 Thread Steve Holden
[EMAIL PROTECTED] wrote: On Nov 10, 1:21 pm, Steve Holden [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: On Nov 10, 8:57 am, Steve Holden [EMAIL PROTECTED] wrote: Robin Becker wrote: ...snip... In old style python there was a sort of standard behaviour whereby None was comparable with

Re: Python 3.0 - is this true?

2008-11-10 Thread Steven D'Aprano
On Mon, 10 Nov 2008 12:51:51 +, Duncan Grisby wrote: I have an object database written in Python. It, like Python, is dynamically typed. It heavily relies on being able to sort lists where some of the members are None. To some extent, it also sorts lists of other mixed types. It will be

Re: Python 3.0 - is this true?

2008-11-10 Thread Steven D'Aprano
On Mon, 10 Nov 2008 11:43:59 -0800, Rhamphoryncus wrote: You might as well comment out the sort and call it good. That's what you really had in 2.x. It was close enough most of the time to *look* right, yet in truth it silently failed. 3.0 makes it an explicit failure. I don't doubt that

Re: Python 3.0 - is this true?

2008-11-10 Thread Rhamphoryncus
On Nov 10, 6:25 pm, Steven D'Aprano [EMAIL PROTECTED] wrote: On Mon, 10 Nov 2008 11:43:59 -0800, Rhamphoryncus wrote: You might as well comment out the sort and call it good.  That's what you really had in 2.x.  It was close enough most of the time to *look* right, yet in truth it silently

Re: Python 3.0 - is this true?

2008-11-10 Thread Rhamphoryncus
On Nov 10, 9:31 pm, Rhamphoryncus [EMAIL PROTECTED] wrote: On Nov 10, 6:25 pm, Steven D'Aprano [EMAIL PROTECTED] wrote: On Mon, 10 Nov 2008 11:43:59 -0800, Rhamphoryncus wrote: You might as well comment out the sort and call it good.  That's what you really had in 2.x.  It was close

Re: Python 3.0 - is this true?

2008-11-10 Thread Tim Roberts
Steven D'Aprano [EMAIL PROTECTED] wrote: On Sat, 08 Nov 2008 22:53:14 -0800, Kay Schluehr wrote: How often do you care about equality ignoring order for lists containing arbitrary, heterogeneous types? A few times. Why do you care, Steven? I'm a very caring kind of guy. That's the best

Re: Python 3.0 - is this true?

2008-11-09 Thread Arnaud Delobelle
Kay Schluehr [EMAIL PROTECTED] writes: On 9 Nov., 07:06, Steven D'Aprano [EMAIL PROTECTED] [...] In any case, the above doesn't work now, since either L1 or L2 might contain complex numbers. The sorted() trick only works because you're making an assumption about the kinds of things in the

Re: Python 3.0 - is this true?

2008-11-09 Thread Rhamphoryncus
On Nov 8, 10:14 pm, Kay Schluehr [EMAIL PROTECTED] wrote: I guess building a multiset is a little more expensive than just O(n). It is rather like building a dict from a list which is O(k*n) with a constant but small factor k. The comparison is of the same order. To enable the same behavior as

Re: Python 3.0 - is this true?

2008-11-09 Thread Stefan Behnel
Kay Schluehr wrote: On 9 Nov., 07:06, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: How often do you care about equality ignoring order for lists containing arbitrary, heterogeneous types? A few times. Why do you care, Steven? I miss this feature is an unqualified statement,

Re: Python 3.0 - is this true?

2008-11-09 Thread Duncan Booth
Steven D'Aprano wrote: Not sure how to transform it into a search key that is efficient and reliable. Yes, that's a general problem. It's not always easy to convert a sort comparison function into a key-based sort. I know that 99% of the time key is the right way to do custom sorts, but

Re: Python 3.0 - is this true?

2008-11-09 Thread Roy Smith
In article [EMAIL PROTECTED], Terry Reedy [EMAIL PROTECTED] wrote: Yes, key= lets you sort anything anyway you want. l=[1, '2', 3j] sorted(l, key = str) [1, '2', 3j] The problem here is that str() is degenerate, i.e. a != b does not imply str(a) != str(b). sorted(l, key = id)

Re: Python 3.0 - is this true?

2008-11-09 Thread Diez B. Roggisch
Also, I thought that part of the python philosophy was to allow any sort of object in a list, and to allow the same methods to work with whatever was in list. Not really. When the usual argument about the existence (and justification) of lists tuples comes along, one common distinction is

Re: Python 3.0 - is this true?

2008-11-09 Thread Kay Schluehr
On 9 Nov., 09:26, Rhamphoryncus [EMAIL PROTECTED] wrote: On Nov 8, 10:14 pm, Kay Schluehr [EMAIL PROTECTED] wrote: I guess building a multiset is a little more expensive than just O(n). It is rather like building a dict from a list which is O(k*n) with a constant but small factor k. The

Re: Python 3.0 - is this true?

2008-11-09 Thread Roy Smith
In article [EMAIL PROTECTED], Diez B. Roggisch [EMAIL PROTECTED] wrote: Also, I thought that part of the python philosophy was to allow any sort of object in a list, and to allow the same methods to work with whatever was in list. Not really. When the usual argument about the

Re: Python 3.0 - is this true?

2008-11-09 Thread Duncan Booth
Roy Smith wrote: In 3.0, can you still order types? In 2.x, you can do: t1 = type(1) t2 = type(1j) t1 t2 False If this still works in 3.0, then you can easily do something like: def total_order(o1, o2): Compare any two objects of arbitrary types try: return o1 = o2

Re: Python 3.0 - is this true?

2008-11-09 Thread Diez B. Roggisch
Roy Smith schrieb: In article [EMAIL PROTECTED], Diez B. Roggisch [EMAIL PROTECTED] wrote: Also, I thought that part of the python philosophy was to allow any sort of object in a list, and to allow the same methods to work with whatever was in list. Not really. When the usual argument about

Re: Python 3.0 - is this true?

2008-11-09 Thread Stefan Behnel
Duncan Booth wrote: Roy Smith wrote: In 3.0, can you still order types? In 2.x, you can do: t1 = type(1) t2 = type(1j) t1 t2 False If this still works in 3.0, then you can easily do something like: def total_order(o1, o2): Compare any two objects of arbitrary types try:

Re: Python 3.0 - is this true?

2008-11-09 Thread Roy Smith
In article [EMAIL PROTECTED], Diez B. Roggisch [EMAIL PROTECTED] wrote: Roy Smith schrieb: In article [EMAIL PROTECTED], Diez B. Roggisch [EMAIL PROTECTED] wrote: Also, I thought that part of the python philosophy was to allow any sort of object in a list, and to allow the same

Re: Python 3.0 - is this true?

2008-11-09 Thread Roy Smith
In article [EMAIL PROTECTED], Duncan Booth [EMAIL PROTECTED] wrote: Roy Smith wrote: In 3.0, can you still order types? In 2.x, you can do: t1 = type(1) t2 = type(1j) t1 t2 False If this still works in 3.0, then you can easily do something like: def total_order(o1, o2):

Re: Python 3.0 - is this true?

2008-11-09 Thread Marc 'BlackJack' Rintsch
On Sun, 09 Nov 2008 10:45:31 -0500, Roy Smith wrote: In article [EMAIL PROTECTED], Diez B. Roggisch [EMAIL PROTECTED] wrote: Roy Smith schrieb: In article [EMAIL PROTECTED], Diez B. Roggisch [EMAIL PROTECTED] wrote: When I wrote uniform I meant objects of the same kind. So for example

Re: Python 3.0 - is this true?

2008-11-09 Thread Marc 'BlackJack' Rintsch
On Sun, 09 Nov 2008 10:45:31 -0500, Roy Smith wrote: In article [EMAIL PROTECTED], Diez B. Roggisch [EMAIL PROTECTED] wrote: Roy Smith schrieb: In article [EMAIL PROTECTED], Diez B. Roggisch [EMAIL PROTECTED] wrote: When I wrote uniform I meant objects of the same kind. So for example

Re: Python 3.0 - is this true?

2008-11-09 Thread Marc 'BlackJack' Rintsch
On Sun, 09 Nov 2008 10:45:31 -0500, Roy Smith wrote: In article [EMAIL PROTECTED], Diez B. Roggisch [EMAIL PROTECTED] wrote: Roy Smith schrieb: In article [EMAIL PROTECTED], Diez B. Roggisch [EMAIL PROTECTED] wrote: When I wrote uniform I meant objects of the same kind. So for example

Re: Python 3.0 - is this true?

2008-11-09 Thread Marc 'BlackJack' Rintsch
On Sun, 09 Nov 2008 10:45:31 -0500, Roy Smith wrote: In article [EMAIL PROTECTED], Diez B. Roggisch [EMAIL PROTECTED] wrote: Roy Smith schrieb: In article [EMAIL PROTECTED], Diez B. Roggisch [EMAIL PROTECTED] wrote: When I wrote uniform I meant objects of the same kind. So for example

Re: Python 3.0 - is this true?

2008-11-09 Thread Terry Reedy
Kay Schluehr wrote: On 9 Nov., 05:04, Terry Reedy [EMAIL PROTECTED] wrote: Have you written any Python code where you really wanted the old, unpredictable behavior? Sure: I was asking the OP ;-) if len(L1) == len(L2): return sorted(L1) == sorted(L2) # check whether two lists

Re: Python 3.0 - is this true?

2008-11-09 Thread Hallvard B Furuseth
Steven D'Aprano writes: How often do you care about equality ignoring order for lists containing arbitrary, heterogeneous types? Arbitrary, I never have. Different types of my choice, a few times. I was only interested in there being some _sort_ order (and the same in different runs of the

Re: Python 3.0 - is this true?

2008-11-09 Thread Hallvard B Furuseth
Terry Reedy writes: If you want to duplicate 2.x behavior, which does *not* work for all types... def py2key(item): return (str(type(item)), item) Nope. sorted((-1, 2, True, False)) == [-1, False, True, 2] sorted((-1, 2, True, False), key=py2key) == [False, True, -1, 2] Might

Re: Python 3.0 - is this true?

2008-11-09 Thread Martin v. Löwis
def comp(x1, x2): try: if x1x2: return -1 else: return 1 except TypeError: if str(x1)str(x2): return -1 else: return 1 Please correct me if I'm wrong, but I think this is not transitive. If strings and ints

Re: Python 3.0 - is this true?

2008-11-09 Thread Martin v. Löwis
Hallvard B Furuseth wrote: Terry Reedy writes: If you want to duplicate 2.x behavior, which does *not* work for all types... def py2key(item): return (str(type(item)), item) Nope. sorted((-1, 2, True, False)) == [-1, False, True, 2] sorted((-1, 2, True, False),

Re: Python 3.0 - is this true?

2008-11-09 Thread Martin v. Löwis
Even in 2.x it doesn't work (I think I posted this earlier but I'm not sure anymore) as this example shows: 2 3j and 3j True, but True 2 What specific value of x have you been trying? For x=4,5,6, I get py 2 3j and 3j True Traceback (most recent call last): File stdin, line 1, in

Re: Python 3.0 - is this true?

2008-11-09 Thread Kay Schluehr
On 9 Nov., 17:49, Terry Reedy [EMAIL PROTECTED] wrote: I was asking the OP ;-) Thank you for the discussion. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3.0 - is this true?

2008-11-09 Thread Aahz
In article [EMAIL PROTECTED], Roy Smith [EMAIL PROTECTED] wrote: In article [EMAIL PROTECTED], Diez B. Roggisch [EMAIL PROTECTED] wrote: attribution missing: Also, I thought that part of the python philosophy was to allow any sort of object in a list, and to allow the same methods to work

Re: Python 3.0 - is this true?

2008-11-09 Thread Martin v. Löwis
In any case, would it be possible to add a cmp= function which did more or less what the current default cmp does now? As somebody pointed out, it's possible to create a key= function that provides arbitrary ordering: just return an object custom type whose __lt__ never fails: class

Re: Python 3.0 - is this true?

2008-11-09 Thread Martin v. Löwis
Hmmm, I seem to have engaged in a bit of topic drift, for which I apologize. I was commenting specifically on the issue of lists holding heterogeneous types, not on heterogeneous types being sortable. Still, I don't think this is a valid counter-example: I claim that the data in the list of

Re: Python 3.0 - is this true?

2008-11-09 Thread Arnaud Delobelle
Roy Smith [EMAIL PROTECTED] writes: I spend too much time in C++ pleading with the compiler to allow me to do what I want. I come to Python to get away from all that type bondage. As another example, consider a list of items being juggled: [RubberChicken(), ChainSaw(), Canteloupe()] I

Re: Python 3.0 - is this true?

2008-11-09 Thread Arnaud Delobelle
Martin v. Löwis [EMAIL PROTECTED] writes: def comp(x1, x2): try: if x1x2: return -1 else: return 1 except TypeError: if str(x1)str(x2): return -1 else: return 1 Please correct me if I'm wrong, but I think

Re: Python 3.0 - is this true?

2008-11-09 Thread Arnaud Delobelle
Martin v. Löwis [EMAIL PROTECTED] writes: Even in 2.x it doesn't work (I think I posted this earlier but I'm not sure anymore) as this example shows: 2 3j and 3j True, but True 2 What specific value of x have you been trying? For x=4,5,6, I get py 2 3j and 3j True Traceback

Re: Python 3.0 - is this true?

2008-11-09 Thread Roy Smith
In article [EMAIL PROTECTED], Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: One added value in Python 3.0 would be that they are sortable in a `list`. But seriously, your token example should work fine with Python 3.0 because the wish to sort tokens is a bit exotic IMHO. Hmmm, I

Re: Python 3.0 - is this true?

2008-11-09 Thread Roy Smith
In article [EMAIL PROTECTED], Martin v. Löwis [EMAIL PROTECTED] wrote: The homogeneous vs. heterogeneous discussion is not that much about type, but more about semantics of the individual values. If you represent (firstname, lastname, age), you use tuples - three different (and orthogonal)

Re: Python 3.0 - is this true?

2008-11-09 Thread Martin v. Löwis
Yes, key= lets you sort anything anyway you want. l=[1, '2', 3j] sorted(l, key = str) [1, '2', 3j] The problem here is that str() is degenerate, i.e. a != b does not imply str(a) != str(b). So why is this a problem? The sort algorithm is stable, so it gives a deterministic result.

Re: Python 3.0 - is this true?

2008-11-09 Thread Martin v. Löwis
Sure: if len(L1) == len(L2): return sorted(L1) == sorted(L2) # check whether two lists contain the same elements else: return False It doesn't really matter here what the result of the sorts actually is as long as the algorithm leads to the same result for all permutations on

Python 3.0 - is this true?

2008-11-08 Thread walterbyrd
I have read that in Python 3.0, the following will raise an exception: [2, 1, 'A'].sort() Will that raise an exception? And, if so, why are they doing this? How is this helpful? Is this new enhancement Pythonic? -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3.0 - is this true?

2008-11-08 Thread Peter Otten
walterbyrd wrote: I have read that in Python 3.0, the following will raise an exception: [2, 1, 'A'].sort() Will that raise an exception? Yes. [2, 1, a].sort() Traceback (most recent call last): File stdin, line 1, in module TypeError: unorderable types: str() int() And, if so,

Re: Python 3.0 - is this true?

2008-11-08 Thread Arnaud Delobelle
walterbyrd [EMAIL PROTECTED] writes: I have read that in Python 3.0, the following will raise an exception: [2, 1, 'A'].sort() Will that raise an exception? Yes. In fact, plenty of objects of different types aren't comparable anymore. And, if so, why are they doing this? How is it

Re: Python 3.0 - is this true?

2008-11-08 Thread Cameron Simpson
On 08Nov2008 19:17, walterbyrd [EMAIL PROTECTED] wrote: | On Nov 8, 12:02 pm, Arnaud Delobelle [EMAIL PROTECTED] wrote: | It goes well with duck typing.  It lets you know when you things happen | that you don't mean to happen. | | But doesn't that also make the language less flexible? No. All

Re: Python 3.0 - is this true?

2008-11-08 Thread Terry Reedy
Steven D'Aprano wrote: On Sat, 08 Nov 2008 19:02:28 +, Arnaud Delobelle wrote: And, if so, why are they doing this? How is it helpful to be able to sort things which have no natural order? Assuming you need to sort arbitrary types, then you have to choose an order, even if it is

Re: Python 3.0 - is this true?

2008-11-08 Thread walterbyrd
On Nov 8, 12:02 pm, Arnaud Delobelle [EMAIL PROTECTED] wrote: It goes well with duck typing.  It lets you know when you things happen that you don't mean to happen. But doesn't that also make the language less flexible? For example, if I used C, I would never have to worry about assigning a

Re: Python 3.0 - is this true?

2008-11-08 Thread walterbyrd
On Nov 8, 7:44 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: Define your own ordering if you need to sort incomparable types. If you starting new, I suppose you can always work around this new enhancement. But, couldn't this cause a lot of backward compatibility issues?

Re: Python 3.0 - is this true?

2008-11-08 Thread Kay Schluehr
On 9 Nov., 05:04, Terry Reedy [EMAIL PROTECTED] wrote: Have you written any Python code where you really wanted the old, unpredictable behavior? Sure: if len(L1) == len(L2): return sorted(L1) == sorted(L2) # check whether two lists contain the same elements else: return False It

Re: Python 3.0 - is this true?

2008-11-08 Thread Terry Reedy
walterbyrd wrote: Guido and the developers changed the behavior of order comparisons, and hence of sorts, because they agreed, on the basis of person-decades of experience, with no dissent that I know of, that the new behavior would be better. Have you written any Python code where you

Re: Python 3.0 - is this true?

2008-11-08 Thread Steven D'Aprano
On Sat, 08 Nov 2008 19:02:28 +, Arnaud Delobelle wrote: And, if so, why are they doing this? How is it helpful to be able to sort things which have no natural order? Assuming you need to sort arbitrary types, then you have to choose an order, even if it is arbitrary, so long as it's

Re: Python 3.0 - is this true?

2008-11-08 Thread Alex_Gaynor
On Nov 8, 11:36 pm, Kay Schluehr [EMAIL PROTECTED] wrote: On 9 Nov., 05:04, Terry Reedy [EMAIL PROTECTED] wrote: Have you written any Python code where you really wanted the old, unpredictable behavior? Sure: if len(L1) == len(L2):     return sorted(L1) == sorted(L2)  # check whether

Re: Python 3.0 - is this true?

2008-11-08 Thread Steven D'Aprano
On Sat, 08 Nov 2008 19:06:14 -0800, walterbyrd wrote: On Nov 8, 7:44 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: Define your own ordering if you need to sort incomparable types. If you starting new, I suppose you can always work around this new enhancement. But,

Re: Python 3.0 - is this true?

2008-11-08 Thread Kay Schluehr
On 9 Nov., 05:49, Alex_Gaynor [EMAIL PROTECTED] wrote: On Nov 8, 11:36 pm, Kay Schluehr [EMAIL PROTECTED] wrote: On 9 Nov., 05:04, Terry Reedy [EMAIL PROTECTED] wrote: Have you written any Python code where you really wanted the old, unpredictable behavior? Sure: if len(L1) ==

Re: Python 3.0 - is this true?

2008-11-08 Thread Steven D'Aprano
On Sat, 08 Nov 2008 20:36:59 -0800, Kay Schluehr wrote: On 9 Nov., 05:04, Terry Reedy [EMAIL PROTECTED] wrote: Have you written any Python code where you really wanted the old, unpredictable behavior? Sure: if len(L1) == len(L2): return sorted(L1) == sorted(L2) # check whether

Re: Python 3.0 - is this true?

2008-11-08 Thread Kay Schluehr
On 9 Nov., 07:06, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Sat, 08 Nov 2008 20:36:59 -0800, Kay Schluehr wrote: On 9 Nov., 05:04, Terry Reedy [EMAIL PROTECTED] wrote: Have you written any Python code where you really wanted the old, unpredictable behavior? Sure:

Re: Python 3.0 - is this true?

2008-11-08 Thread Steven D'Aprano
On Sat, 08 Nov 2008 22:53:14 -0800, Kay Schluehr wrote: How often do you care about equality ignoring order for lists containing arbitrary, heterogeneous types? A few times. Why do you care, Steven? I'm a very caring kind of guy. In any case, the above doesn't work now, since either L1