List Coordinates Between A Set Of Coordinates
This should be fairly easy, but I'm getting a headache from trying to figure it out. I want to list all the coordinates between two points. Like so: 1: (1,1) 2: (1,3) In between: (
Solution 1:
You appear to be a beginning programmer. A general technique I find useful is to do the job yourself, on paper, then look at how you did it and translate that to a program. If you can't see how, break it down into simpler steps until you can.
Solution 2:
Depending on how you want to handle the edge cases, this seems to work:
defpoints_between(p1, p2):
xs = range(p1[0] + 1, p2[0]) or [p1[0]]
ys = range(p1[1] + 1, p2[1]) or [p1[1]]
return [(x,y) for x in xs for y in ys]
print points_between((1,1), (5,1))
# [(2, 1), (3, 1), (4, 1)]print points_between((5,6), (5,12))
# [(5, 7), (5, 8), (5, 9), (5, 10), (5, 11)]
Post a Comment for "List Coordinates Between A Set Of Coordinates"