Last active
August 29, 2015 14:05
-
-
Save szeitlin/fb07eda9113980e7a046 to your computer and use it in GitHub Desktop.
helper script for 'close enough'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| __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