Skip to content

Instantly share code, notes, and snippets.

@cwindolf
Created April 20, 2023 22:14
Show Gist options
  • Save cwindolf/893e13438b0fd294db66a198a461c531 to your computer and use it in GitHub Desktop.
Save cwindolf/893e13438b0fd294db66a198a461c531 to your computer and use it in GitHub Desktop.
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