Skip to content

Instantly share code, notes, and snippets.

@alecbz
Created March 19, 2014 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alecbz/9651803 to your computer and use it in GitHub Desktop.
Save alecbz/9651803 to your computer and use it in GitHub Desktop.
buckets = defaultdict(list)
for z, root in root_from.iteritems():
closest = next((k for k in buckets if abs(k - root) < 1e-3), None)
if closest:
buckets[closest].append(z)
else:
buckets[root].append(z)
roots = buckets.keys()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment