Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created May 24, 2017 10:14
Show Gist options
  • Save zeffii/75a3bbcacd0efe967bc6ea0d9ac9422b to your computer and use it in GitHub Desktop.
Save zeffii/75a3bbcacd0efe967bc6ea0d9ac9422b to your computer and use it in GitHub Desktop.
def some_function(inp, rng):
remaps = [] # you fill this
last_valid = None
for i in range(rng[0], rng[1]+1):
if i < inp[0]:
last_valid = inp[0]
elif i in set(inp):
last_valid = i
elif i >= inp[-1]:
last_valid = inp[-1]
else:
for j in range(len(inp)-1):
begin, end = inp[j], inp[j+1]
if begin < i < end:
last_valid = begin
remaps.append(last_valid)
print(remaps)
mdict = {idx: remaps[idx-1] for idx in range(1, len(remaps)+1)}
print(mdict)
return remaps
input_frames = [5, 8]
start_end = [1, 10]
assert([5, 5, 5, 5, 5, 5, 5, 8, 8, 8] == some_function(input_frames, start_end))
input_frames = [1, 5, 8]
start_end = [1, 10]
assert([1, 1, 1, 1, 5, 5, 5, 8, 8, 8] == some_function(input_frames, start_end))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment