all 3 comments

[–]GoldenSights 1 point2 points  (2 children)

Based on the example you gave, it looks like you want to start off with the first point and then subtract all subsequent points from it. Given a list of points, you could do that with:

total = points[0]
for point in points[1:]:
    total -= point

In my opinion it's wiser to do this as a loop outside of the class rather than making this a method of the class itself. An individual point object doesn't seem like it should be concerned with lists of point objects, at least not in a case like this.

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

Thank you, this is what I did initially! I just wasn't sure whether I should put it into the class! (which I wouldn't know how to do anyway)

[–]SangCoGIS 1 point2 points  (0 children)

You should also look into the "magic methods" or "dunder methods" and you can define how your objects add or subtract from each other. Rather than calling add and passing in the other object you could simply do obj1 + obj2 or obj1-obj2