在列表中查找项目

问题描述 投票:0回答:1

[试图制作一个总是从列表中的列表(至少从顶层列表)中找到两者的程序。这就是我到目前为止所拥有的。

List_Test = [[2]]

if 2 in List_Test:
    print("Found!")
elif 2 in List_Test[0][0]:
    print("Found in an inner list!")
elif 2 not in List_Test:
    print("Not Found.")

我一直想出一个

TypeError of : argument of type 'int' is not iterable 

我在做什么错?

python list pycharm
1个回答
0
投票
List_Test = [[2]]

if 2 in List_Test:
    print("Found!")
elif 2 in List_Test[0]:
    print("Found in an inner list!")
else:
    print("Not Found.")

尝试上面的代码。

[[Noteelif 2 not in List_Test是多余的,不是必需的。

© www.soinside.com 2019 - 2024. All rights reserved.