0
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
Python的循環通過字典:類型錯誤:解壓縮非序列
這是什麼意思?
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
Python的循環通過字典:類型錯誤:解壓縮非序列
這是什麼意思?
您是否正在尋找?
for a, b in sub.iteritems():
# Do Something.
否則
for a, b in sub:
#...
嘗試分配(a, b)
在sub
一個鍵,其可能不是一個序列。
如果可能,使用['iteritems()'](http://docs.python.org/2/library/stdtypes.html#dict.iteritems):) – woozyking
是的。 grrr我正在看的教程是錯誤的然後... – ealeon
iteritems()和items()之間有任何區別嗎? – ealeon