Created
May 18, 2020 00:25
-
-
Save kzinmr/8801b267fee731e4e13aaa2f05439837 to your computer and use it in GitHub Desktop.
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
from itertools import groupby | |
from operator import itemgetter | |
data = [ 1, 4,5,6, 10, 15,16,17,18, 22, 25,26,27,28] | |
consecutive_ints = [map(itemgetter(1), g) for k, g in groupby(enumerate(data), lambda (i, x): i-x)] | |
# [[1], | |
# [4, 5, 6], | |
# [10], | |
# [15, 16, 17, 18], | |
# [22], | |
# [25, 26, 27, 28]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment