Skip to content

Instantly share code, notes, and snippets.

@alecbz
Created March 19, 2014 21:30
Show Gist options
  • 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