Skip to content

Instantly share code, notes, and snippets.

@kmanalo
Created December 3, 2014 15:14
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 kmanalo/10e6aa69a6349b34172c to your computer and use it in GitHub Desktop.
Save kmanalo/10e6aa69a6349b34172c to your computer and use it in GitHub Desktop.
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