这是我的代码的一部分:
if click(pt, rec):
entrytxt = eninput.getText()
if entrytxt in route: # route dict
shapeID = route[entrytxt]
for i in shapeID:
coordinates = shape[i] # shape dict
print(len(coordinates))
----------------------------------------------------------------------------
ourput for len(coordinates):
180
349
339
184
102
405
185
desired output:
405
我试图从坐标中选择长度最长的列表,
并使用该索引从坐标中获取最长的列表。
coordinates 包含许多具有协调值的列表。 (不是列表列表)
如何只打印 405?
答案 0 :(得分:1)
我该如何解决这个问题?
不调用len
?还是使用 len
作为键函数?
您没有真正解释 coordinates
是什么或包含什么。你写的肯定没有任何意义:len()
返回一个整数,所以这个:
ourput for print(len(coordinates)):
180
349
339
184
102
405
185
实际上不可能。含义 max(len(coordinates))
不能在使用单个参数调用 max
时,它必须是可迭代的,(正如错误消息告诉您的那样)整数不是。
答案 1 :(得分:0)
将 print(max(len(coordinates)))
替换为 print(max(coordinates))
。因为 max 期待一个可迭代对象。