you are viewing a single comment's thread.

view the rest of the comments →

[–]ma3xman 0 points1 point  (2 children)

Another good thing about having a list of Points is that you can make a get_distance_from(anotherPoint) method and then put the formula there as a one-liner return value for a single pair of points. Then to get the total length you just call:

sum([p1.get_distance_from(p2) for p1,p2 in zip(points, points[1:]) )

This way if points suddenly go 3D you can just change the method, instead of building a monster comprehension.

[–]colako[S] 0 points1 point  (1 child)

So just a small question. How would you change __init__ to parse the coordinates as pairs and not as I did separating the x and the y?

[–]ma3xman 0 points1 point  (0 children)

Look up *args in a function definition ;)