How to search for an item in a list of lists?

前端 未结 5 765
星月不相逢
星月不相逢 2021-01-25 00:15

How can I do something like this.

index=[[test1,test2,test3],[test4,test5,test6],[test7,test8,test9]]
if test5 is in index:
    print True
5条回答
  •  执念已碎
    2021-01-25 00:34

    Using any + generator expression:

    if any(test5 in subindex for subindex in index):
        print True
    

提交回复
热议问题