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

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

我是新人,不懂事。我想制作一个新的列表,列出我拥有的每个坐标之间的距离,一个点 1-点 2、点 1-点 3、点 2-点 3 的距离列表。

所以我的代码是:

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 当我尝试 运行 它时,它说:

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

如何正确地运行?谢谢!

正如我在 documentation 中看到的那样,geodesic 接受多个参数,例如 *args.

所以尝试解包:

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

或解包迭代:

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