Search code examples
pythoncoordinatestypeerrordistancegeopy

geopy.distance.geodesic() but it says TypeError: unsupported operand type(s) for +=: 'int' and 'tuple'


I'm new and don't understand things. I want to make a new list of distances between every coordinates I have, a list of the distances of point1-point2, point1-point3, point2-point3.

so my code is:

list_of_coords = [(5.55, 95.3175), (3.583333, 98.666667), (-0.95556, 100.36056)]

list_of_distances = [geopy.distance.geodesic(combo).km for combo in combinations(list_of_coords,2)]

anddd when I try to run it, it says:

TypeError: unsupported operand type(s) for +=: 'int' and 'tuple'

How to make it run properly? Thank you!


Solution

  • As I can see in the documentation, geodesic takes multiple arguments, like *args.

    So try unpacking:

    list_of_distances = [geopy.distance.geodesic(*combo).km for combo in combinations(list_of_coords, 2)]
    

    Or unpack iteration:

    list_of_distances = [geopy.distance.geodesic(a, b).km for a, b in combinations(list_of_coords, 2)]