Skip to content

Instantly share code, notes, and snippets.

@scw
Created April 25, 2018 21:53
Show Gist options
  • Save scw/9a8b1c83cdbaadd4358f8c450a2e0dda to your computer and use it in GitHub Desktop.
Save scw/9a8b1c83cdbaadd4358f8c450a2e0dda to your computer and use it in GitHub Desktop.
x = [5, 10, 15, 20, 30, 40, 50, 60, 100, 140]
def range_finder(seq):
it = iter(seq)
prev = next(it)
prev_diff = seq[1] - seq[0]
r = 0
for (i, item) in enumerate(it):
diff = item - prev
if diff != prev_diff:
print("range step {} of len {}".format(prev_diff, r))
prev_diff = diff
r = 0
prev = item
r += 1
# emit final range
if i == len(seq) - 2:
print("range step {} of len {}".format(prev_diff, r))
range_finder(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment