Created
April 25, 2018 21:53
-
-
Save scw/9a8b1c83cdbaadd4358f8c450a2e0dda 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
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