I have two lists of coordinates,
lat = [-23.23, -44.23, -12.23]
lon = [-21.23, -14.23, -62.23]
and I generate a tuple of lat long
pairs with zip
:
latlon = zip(lat, lon)
and that gives the expected result. Now there is a very common pattern of generating lines with the points. It is common to do something like
line_coords = []
for i in xrange(len(coords)-1):
line_coords.append([tuple(coords[i]), tuple(coords[i+1])])
so the result is now a list of tuples, each tuple an list of beginning and end of a line:
line_coords
[[(-23.23, -21.23), (-44.23, -14.23)], [(-44.23, -14.23), (-12.23, -62.23)] ]
and it get worse if the line needs to come back to the beginning. This looks like an anti-pattern. Is there a name for this pattern and a more elegant way to do it?
latlon
instead ofcoords
? \$\endgroup\$latlon
could be passed to a function defined along the lines ofdef whatever(coords):
. \$\endgroup\$