[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2010-07-20 Thread METAL XXX
METAL XXX added the comment: Shame on me, after a long time I realized the problem referenced in my old post (http://bugs.python.org/msg102019) was actually topological sorting. It can't be done by Python's sort(), which doesn't support partial order. Trying to use cmp parameter is completely

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2010-03-31 Thread R. David Murray
R. David Murray added the comment: cmp is gone. It's chances of coming back are close enough to zero that an assertAlmostEqual test will pass :). The rest of the discussion should move to one of the general python lists. -- nosy: +r.david.murray

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2010-03-31 Thread METAL XXX
METAL XXX added the comment: Sorry I ripped the code from a mess and I forget the tree is "leaflized" as tree = { 'A': set(['B', 'C', 'D', 'E']), 'B': set(['D', 'E']), 'C': set(), 'D': set(), 'E': set(), } I don't want to talk about the actual problem. I think sometime it's hard to

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2010-03-31 Thread Guido van Rossum
Changes by Guido van Rossum : -- nosy: -gvanrossum ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2010-03-31 Thread David Albert Torpey
David Albert Torpey added the comment: > sorted(tree, cmp=lambda x, y: 1 if x in tree[y] else -1 if y in tree[x] else > 0) > > and it gets ['A', 'C', 'B', 'E', 'D']. That cmp function is nonsense and isn't even close to being correct: >>> from random import shuffle >>> for i in range(10): ...

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2010-03-31 Thread METAL XXX
METAL XXX added the comment: I have a tree: A / \ B C / \ D E which is implemented as a dict tree = { 'A': set(['B', 'C']), 'B': set(['D', 'E']), 'C': set(), 'D': set(), 'E': set(), } I want to sort the nodes. and I don't know how to write a key function for sort() in thi

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2009-12-07 Thread Guido van Rossum
Guido van Rossum added the comment: Python's sort implementation is carefully written to only use the "<" comparison, ever. So a cmp really isn't the most natural way to specify a comparison. (This should really be documented somewhere -- I know know it because Tim Peters & I shared an offi

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2009-12-07 Thread Guido van Rossum
Changes by Guido van Rossum : Removed file: http://bugs.python.org/file15473/unnamed ___ Python tracker ___ ___ Python-bugs-list mailing list U

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2009-12-07 Thread Guido van Rossum
Changes by Guido van Rossum : Removed file: http://bugs.python.org/file15463/unnamed ___ Python tracker ___ ___ Python-bugs-list mailing list U

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2009-12-07 Thread Tom Switzer
Tom Switzer added the comment: If the equal min y-coords are handled, I think it'd be quicker too. As Guido noted, O(n) function calls is better then O(n log n) =] Though the general case is still unhandled. And, though it doesn't help my case, the Graham Scan can also be performed on points sor

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2009-12-06 Thread Mark Dickinson
Mark Dickinson added the comment: Ah. Thanks for the explanation; I see your point. I guess you do just have to use a CmpToKey-type wrapper for this sort of comparison. Though for this *particular* example, it seems to me that you could still use a key function lambda q: (q[0] - p[0])/(q[

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2009-12-06 Thread Tom Switzer
Tom Switzer added the comment: Mark: I think your example actually helps illustrate my point. My point was that computing the angle directly is less efficient or not as nice numerically. For instance, if you are sorting points by angle relative to an extreme point you could do something like thi

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2009-12-06 Thread Mark Dickinson
Mark Dickinson added the comment: Tom, I think I'm missing your point: all three of the examples you give seem like perfect candidates for a key-based sort rather than a comparison-based one. For the first example, couldn't you do something like: def direction(pt1, pt2): """angle of li

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2009-12-04 Thread Raymond Hettinger
Raymond Hettinger added the comment: FWIW, we had a long discussion on comp.lang.python and the net result was that no use cases were found that required a cmp function. One complex case (sorting recursive tree structures) at first appeared to need a cmp-function but was found to be simpler and

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2009-12-04 Thread Guido van Rossum
Guido van Rossum added the comment: Can someone provide a code sample to make this argument more understandable for those of us who don't compare points by angular order for a living... :-) I'm not sure what the 2to3 example (I presume you mean msg59937) shows except that conversion from a c

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2009-12-04 Thread Tom Switzer
Tom Switzer added the comment: I am not sure I understand the reasoning behind removing the cmp parameter (and agree with Lea Wiemann). Trying to wedge a proper comparison into the key parameter is clumsy and unreadable (as can be seen in the 2to3 example above). The intrinsic ordering on object

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2008-02-16 Thread Lea Wiemann
Lea Wiemann added the comment: I know, but I don't always want to define the comparison on the object itself, because it's not an intrinsic feature of the object. It's just the way I happen to sort it right now. (That's especially likely if the ordering algorithm is complex.) __

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2008-02-16 Thread Raymond Hettinger
Raymond Hettinger added the comment: FWIW, an object with a complex element-to-element comparison can define an __lt__() method and have it work with sort, min, max, etc. __ Tracker <[EMAIL PROTECTED]> __

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2008-02-16 Thread Raymond Hettinger
Changes by Raymond Hettinger: __ Tracker <[EMAIL PROTECTED]> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/p

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2008-02-16 Thread Lea Wiemann
Lea Wiemann added the comment: "Non-obvious" to the novice that this technique can be used, and non- obvious to the reader of the program. I'm envisioning key functions that return long sequences of -1/0/1 integers, or numbers between 0 and 2**50... Not good. Instead of removing cmp, I'd sugg

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2008-02-16 Thread Lea Wiemann
Lea Wiemann added the comment: Is this really necessary? I see that the sorting code gets a little simpler, but I believe that there are valid use cases for cmp out there, where using a key would at least be cumbersome. So why remove it when it's useful? For instance, if you have an algorith

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2008-01-30 Thread Raymond Hettinger
Changes by Raymond Hettinger: -- status: open -> closed __ Tracker <[EMAIL PROTECTED]> __ ___ Python-bugs-list mailing list Unsubscribe: http:

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2008-01-30 Thread Raymond Hettinger
Raymond Hettinger added the comment: Checked-in rev 60453. __ Tracker <[EMAIL PROTECTED]> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2008-01-14 Thread Guido van Rossum
Guido van Rossum added the comment: > After more thought, I would like to make one more change and require the > arguments to be keywords such as sort(key=str.lower) but not > sort(str.lower). Works for me. (To be honest I thought key was already required to be a keyword. :-) __

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2008-01-14 Thread Raymond Hettinger
Raymond Hettinger added the comment: Yes, it does feel great. The code is cleaner and faster. The API is simple and matches all the other key= functions in min/max/nsmallest/nlargest/groupby. After more thought, I would like to make one more change and require the arguments to be keywords such

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2008-01-13 Thread Guido van Rossum
Guido van Rossum added the comment: Cool! Doesn't it feel good to rip out stuff? :-) I do hope that you'll make sure all tests pass (-uall) before submitting this. __ Tracker <[EMAIL PROTECTED]>

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2008-01-13 Thread Raymond Hettinger
Raymond Hettinger added the comment: Patch attached for the C files making them much cleaner and a bit faster. Still needs the related tests to be deleted and the docs updated. Added file: http://bugs.python.org/file9155/nocmp.diff __ Tracker <[EMAIL PROTECTED]

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2008-01-13 Thread Raymond Hettinger
Raymond Hettinger added the comment: Let's do this. It is a nice simplification and makes the sort tools easier to learn and use. -- assignee: -> rhettinger resolution: -> accepted __ Tracker <[EMAIL PROTECTED]> _

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2008-01-08 Thread Raymond Hettinger
Raymond Hettinger added the comment: Forgot to mention, the easy work-around is to do two consecutive sorts and take advantage of the guaranteed stability: l.sort(key=secondary, reverse=True) l.sort(key=primary) __ Tracker <[EMAIL PROTECTED]>

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2008-01-08 Thread Raymond Hettinger
Raymond Hettinger added the comment: I support removal; however, there is an uncommon corner-case that is well served by __cmp__ where a primary key is sorted ascending and a secondary key is sorted descending -- that case is a PITA with the key= function because you need a way to invert the sen

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2008-01-08 Thread Guido van Rossum
Changes by Guido van Rossum: -- components: +Interpreter Core __ Tracker <[EMAIL PROTECTED]> __ ___ Python-bugs-list mailing list Unsubscribe:

[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2008-01-08 Thread Guido van Rossum
New submission from Guido van Rossum: We should either change the API so you can pass in a '<' comparator, or get rid of it completely (since key=... takes care of all use cases I can think of). -- messages: 59575 nosy: gvanrossum priority: normal severity: normal status: open title: Rem