列表中的ValueError

2024-04-26 11:47:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在计算从中心到中心的距离

dist = [sqrt(p*p + q*q) for p, q in (x, y)]

但是,得到ValueError: too many values to unpack (expected 2)。你知道吗

x&y是具有x,y坐标值的列表。你知道吗


Tags: toin距离列表fordistsqrt中心
2条回答

^{}非常适合:

>>> list(map(lambda p,q:sqrt(p*p + q*q), x, y))
[4.123105625617661, 5.385164807134504, 6.708203932499369]

尝试使用^{}

dist = [sqrt(p*p + q*q) for p, q in zip(x, y)]

相关问题 更多 >