Skip to content

Instantly share code, notes, and snippets.

@lx-88
Created July 31, 2015 18:31
Show Gist options
  • Save lx-88/85b2e485bd21275a8c6c to your computer and use it in GitHub Desktop.
Save lx-88/85b2e485bd21275a8c6c to your computer and use it in GitHub Desktop.
Moving window for a nested python list
# Test fixture for lineStrings
lineStrings = [(i, "obj{0}".format(i),) for i in range(1011)]
stepSize = 200
nSteps = len(lineStrings)/stepSize
print "there are {0} objs in lineStrings".format(len(lineStrings))
steps = range(0, nSteps+1)
for stepI in steps:
# Get the first object in the window
firstObj_i = stepSize*stepI
firstObj = lineStrings[firstObj_i]
# Get the next object
try:
nextObj_i = stepSize*(steps[stepI+1])-1
nextObj = lineStrings[nextObj_i]
except IndexError:
nextObj = lineStrings[-1]
print "firstObj: {0}\t\tnextObj: {1}".format(firstObj, nextObj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment