I am very new to Python. I have a function DISTANCE(lat1, long1, lat2, long2) that calculates the distance between 2 points.
Then I have a list called POINTS, where each value is another list which contains those four values.
I would like to obtain the sum of the results of the function DISTANCE for all the values inside POINTS.
Can anybody help me with that? Thanks!
sum(DISTANCE(*p) for p in POINTS)
The * here is the syntax for Unpacking Argument Lists, also called the splat operator. This passes the contents of an iterable as the positional arguments to a function, so if p were [1, 2, 3, 4], DISTANCE(*p) would be the same as DISTANCE(1, 2, 3, 4).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With