faster sorting syntax in python, try/except for py 2.3 backwards compat

ls.sort(key = lambda v: v.foo)
rather then
  ls.sort(lambda a,b: cmp(a.foo, b.foo))
This commit is contained in:
2006-12-14 14:53:32 +00:00
parent 4b99060cc3
commit b995593eee
8 changed files with 52 additions and 18 deletions

View File

@@ -162,7 +162,9 @@ def convexHull(point_list_2d):
# Get a local list copy of the points and sort them lexically.
points = [(p, i) for i, p in enumerate(point_list_2d)]
points.sort(lambda a,b: cmp((a[0].x, a[0].y), (b[0].x, b[0].y)))
try: points.sort(key = lambda a: (a[0].x, a[0].y))
except: points.sort(lambda a,b: cmp((a[0].x, a[0].y), (b[0].x, b[0].y)))
# Build upper half of the hull.
upper = [points[0], points[1]] # cant remove these.