Created
December 3, 2014 15:14
-
-
Save kmanalo/10e6aa69a6349b34172c to your computer and use it in GitHub Desktop.
This file contains 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
import operator | |
import itertools | |
def contiguous_range(data): | |
""" determine continguous ranges of integer data """ | |
cr_data = [] | |
for k, g in itertools.groupby(enumerate(data), lambda (i,x):i-x): | |
cr_data.append(map(operator.itemgetter(1), g)) | |
return cr_data | |
data = [ 1, 4,5,6, 10, 15,16,17,18, 22, 25,26,27,28] | |
print contiguous_range(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment