Skip to content

Instantly share code, notes, and snippets.

@szeitlin
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save szeitlin/fb07eda9113980e7a046 to your computer and use it in GitHub Desktop.

Select an option

Save szeitlin/fb07eda9113980e7a046 to your computer and use it in GitHub Desktop.
helper script for 'close enough'
__author__ = 'szeitlin'
#helper script to designate allowed range for grouping
def delta_range(delta):
'''
Takes a delta and applies it to generate a reference list for grouping items.
(int) --> list of ints (except zero)
>>> delta_range(2)
[-1, 1]
>>> delta_range(10)
[-5, -4, -3, -2, -1, 1, 2, 3, 4, 5]
'''
half = delta//2
right = [x for x in range(1, half+1)]
left = [-x for x in range(1, half+1)]
left.reverse()
both = left + right
return both
import doctest
doctest.testmod()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment