Skip to content

Instantly share code, notes, and snippets.

@kzinmr
Created May 18, 2020 00:25
Show Gist options
  • Save kzinmr/8801b267fee731e4e13aaa2f05439837 to your computer and use it in GitHub Desktop.
Save kzinmr/8801b267fee731e4e13aaa2f05439837 to your computer and use it in GitHub Desktop.
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