Skip to content

Instantly share code, notes, and snippets.

@markgajdosik
Created October 11, 2017 16:21
Show Gist options
  • Save markgajdosik/f5ca2b167f322c50911a8de30973db2d to your computer and use it in GitHub Desktop.
Save markgajdosik/f5ca2b167f322c50911a8de30973db2d to your computer and use it in GitHub Desktop.
Less Crazy
l = [1, 2, 3, 4, 6, 7, 8, 10, 12]
ranges, last = [], None
for i in l:
if last is None or i - last > 1:
ranges.append([i, i])
else:
ranges[-1][1] = i
last = i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment