我想逐行打印以下字典,其中第二行应该是列表本身(在 Python 2x 中):
dict = {1: [10, 20, 30], 2: [40, 50]}
for i in dict:
print ("i = %s" % i)
for j in dict[i]:
print dict[i][j]
print ("\n")
这是通过遵循这个答案,但仍然有这个超出范围的错误!
i = 1
Traceback (most recent call last):
File "./t.py", line 26, in <module>
print dict[i][j]
IndexError: list index out of range
我正在自学Python。如果这个问题对你们大多数人来说微不足道,我深表歉意。