这是我的功能:
def printSubnetCountList(countList):
print type(countList)
for k, v in countList:
if value:
print "Subnet %d: %d" % key, value
这是通过传递给字典的函数调用该函数时的输出:
<type 'dict'>
Traceback (most recent call last):
File "compareScans.py", line 81, in <module>
printSubnetCountList(subnetCountOld)
File "compareScans.py", line 70, in printSubnetCountList
for k, v in countList:
TypeError: 'int' object is not iterable
有任何想法吗?
最佳答案
试试这个
for k in countList:
v = countList[k]
或这个
for k, v in countList.items():
请阅读以下内容:Mapping Types —
dict
— Python documentation关于python - Python:遍历字典可得 “int object not iterable”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5750664/