Created
April 20, 2023 22:14
-
-
Save cwindolf/893e13438b0fd294db66a198a461c531 to your computer and use it in GitHub Desktop.
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
def runs_to_ranges(x, one_more=False): | |
ranges = [] | |
cur = x[0] | |
b = x[0] | |
for a, b in zip(x, x[1:]): | |
assert b > a | |
if b - a == 1: | |
continue | |
else: | |
ranges.append(range(cur, a + 1 + one_more)) | |
cur = b | |
ranges.append(range(cur, b + 1 + one_more)) | |
return ranges |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment