Last active
September 22, 2017 15:34
-
-
Save osvalr/7483b46eebd2b9dc292a082cd3e68a48 to your computer and use it in GitHub Desktop.
recognize gaps in a list of sequences of numbers, and group them
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
#!/usr/sbin/python | |
# Taken from Python examples: https://docs.python.org/2.6/library/itertools.html#examples | |
from operator import itemgetter | |
from itertools import groupby | |
data_list = [[1,3], [1, 2, 3], [3]] | |
for data in data_list: | |
for k, g in groupby(enumerate(data), lambda ix :ix[0]-ix[1]): | |
print map(itemgetter(1), g) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment