Created
July 31, 2015 18:31
-
-
Save lx-88/85b2e485bd21275a8c6c to your computer and use it in GitHub Desktop.
Moving window for a nested python list
This file contains hidden or 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
# 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