Created
October 11, 2017 16:21
-
-
Save markgajdosik/f5ca2b167f322c50911a8de30973db2d to your computer and use it in GitHub Desktop.
Less Crazy
This file contains 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
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