Python循环遍历字典:TypeError:unpack non-sequence

时间:2013-07-24 16:41:17

标签: python dictionary

sub = {} 
for a, b in sub:                   #<--- error occurs here
   for s in b:
       #do blah. I was told a b is a list

它给了我TypeError: unpack non-sequence

这是什么意思?

1 个答案:

答案 0 :(得分:4)

你在找这个吗?

for a, b in sub.iteritems():
    # Do Something.

否则

for a, b in sub:
    #...

尝试将(a, b)分配给sub中可能不是序列的密钥。