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

前端 未结 5 799
星月不相逢
星月不相逢 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:38

    Or perhaps try itertools to unroll the array :-

    index=[[test1,test2,test3],[test4,test5,test6],[test7,test8,test9]]
    if test5 in itertools.chain(*index):
        print True
    

提交回复
热议问题