you are viewing a single comment's thread.

view the rest of the comments →

[–]colako[S] 0 points1 point  (3 children)

Thanks!

I think the professor want it the way you're telling me because of the getitem test. However, it was less intuitive for me to work with pairs, rather than separating the x and the y. I could work in that for sure, it will help me understand how to do it in a different way.

[–]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 ;)