python - TypeError:“int”对象不可在 for 循环中使用 max 函数进行迭代
问题描述
这是我的代码的一部分:
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
我试图从坐标中选择最长的列表,
并使用该索引从坐标中获取最长的列表。
坐标包含许多具有协调值的列表。(不是列表列表)
我怎样才能只打印出 405?
解决方案
我怎么能解决这个问题?
通过不打电话len
?还是通过len
用作键功能?
您并没有真正解释什么coordinates
是或包含什么。你写的当然没有任何意义:len()
返回一个整数,所以:
ourput for print(len(coordinates)):
180
349
339
184
102
405
185
实际上不可能。当使用单个参数调用时,含义max(len(coordinates))
也不能max
,它必须是可迭代的,(正如错误消息告诉您的那样)整数不是。
推荐阅读
- javascript - 如何使“我”元素仅在您第一次使用 javascript 加载主页时显示?
- javascript - 无法将字符串变量添加为函数参数
- javascript - 隐藏或删除对象属性
- php - 如果多行字段包含 MySQL 中的单词,则从多行字段中删除一行
- java - 如何使用 bufferedreader 和 treemap 打印文本中最常见的单词?- 爪哇
- react-native - 如何在原生基地的手风琴面板之间添加空间
- python - 无法从另一个源代码调用函数
- angular - 为每条路线自动添加语言 ID
- networking - 使用 DPDK 将数据包数据写入文件会导致丢包(即使流量速度 <200 Mbps)。瓶颈是什么?
- node.js - 如何为不和谐服务器制作“!踢”命令消息?