'int' object is not iterable 仍然存在问题
Still problem with 'int' object is not iterable
感谢您的提示,我在 python3 中有以下代码,但我一直遇到相同的错误 "int" is not iterable,您知道问题出在哪里吗?
formatRequiredNewH={(101, 1): [2, 3], (102, 3): [3], (103, 2): [2], (104, 3): [1], (105, 2): [777]}
fixedUniqueCompilation=[1,2,3,4,5]
try:
for actClass in list(formatRequiredNewH.keys()):
for h in fixedUniqueCompilation:
print(formatRequiredNewH[actClass])
if 2 in formatRequiredNewH[actClass][0]:
print("Works?")
except:
print("not")
if 2 == formatRequiredNewH[actClass][0]:
etc..
in 意味着 python 它应该查看一个可迭代对象。 ;)
例如,除非您正在寻找 102 中的 2,然后您需要从 int 转换为 string :
if '2' in str(formatRequiredNewH[actClass][0]):
感谢您的提示,我在 python3 中有以下代码,但我一直遇到相同的错误 "int" is not iterable,您知道问题出在哪里吗?
formatRequiredNewH={(101, 1): [2, 3], (102, 3): [3], (103, 2): [2], (104, 3): [1], (105, 2): [777]}
fixedUniqueCompilation=[1,2,3,4,5]
try:
for actClass in list(formatRequiredNewH.keys()):
for h in fixedUniqueCompilation:
print(formatRequiredNewH[actClass])
if 2 in formatRequiredNewH[actClass][0]:
print("Works?")
except:
print("not")
if 2 == formatRequiredNewH[actClass][0]:
etc..
in 意味着 python 它应该查看一个可迭代对象。 ;)
例如,除非您正在寻找 102 中的 2,然后您需要从 int 转换为 string :
if '2' in str(formatRequiredNewH[actClass][0]):