的名单这里是我的(名单)名单:嵌套if语句返回没有在名单
mylist = [ [1, "John", None, "Doe"], [2, "Jane", "group1", "Zee"], [3, "Lex", "group2", "Fee"]]
y = 2
for sublist in mylist:
if sublist[0] == y: # meaning the third list
if sublist[2] == None:
print(sublist[2]) # this should print nothing
else:
print(sublist[2]) #this should print something
最终的结果是,此代码不能打印任何内容。
我试图做的,我有我的(列表)列表中None
值的情况进行检查。上面的这个方法似乎不起作用。
我想不通为什么它拒绝停止打印任何东西,但我相信嵌套if sublist[2] == None:
可能有一些用它做。
这会在我的机器上打印“group1”。使用python 3.4。 –
'sublist [0] == y',因为'y = 2',* second *列表将为真。 –
我使用python 2.7,你的代码打印'group1' –