Mark Dickinson <dicki...@gmail.com> 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[1]-p[1]), which would be even more efficient. This is assuming that your extreme point p has minimal second coordinate amongst points being sorted, which as I understand it is how the Graham Scan typically starts. There's the minor difficulty of dealing with points with the *same* second coordinate as p, where I guess the key value should be some form of +Infinity. I can also see that this might be problematic if you're working with a type that's exact for addition and multiplication but not for division (e.g., Decimal with unbounded precision). It would be interesting to see some relative timings for the sort stage of the Graham scan (on a million random points, say): key function versus cmp function. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue1771> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com