小编Dan*_*Dan的帖子

Python:通过字典迭代给我"int object not iterable"

这是我的功能:

def printSubnetCountList(countList):
    print type(countList)
    for k, v in countList:
        if value:
            print "Subnet %d: %d" % key, value
Run Code Online (Sandbox Code Playgroud)

这是通过传递给它的字典调用函数时的输出:

<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
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

python dictionary loops

34
推荐指数
2
解决办法
4万
查看次数

Python:打印没有括号和单引号的列表?

我有一个充满IP地址的列表.我想遍历列表并打印每个IP地址.当我尝试这样做时:

def printList(theList):
    for item in theList:
        print item
Run Code Online (Sandbox Code Playgroud)

输出看起来像这样:

['8.0.226.5']
['8.0.247.5']
['8.0.247.71']
['8.0.249.28']
['8.0.249.29']
Run Code Online (Sandbox Code Playgroud)

我已经尝试了一切,包括循环中的"print item [0]".我究竟做错了什么?

python printing loops list

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

loops ×2

python ×2

dictionary ×1

list ×1

printing ×1