我试图让 Python 在我的列表中搜索包含我的两个搜索词的子列表,但是我得到了包含一个或多个搜索的任何子列表。这是我的代码:
search1 = 4
search2 = 3
data = [[4,3],[4,7], [6,3], [9,2]]
found = False
for sublist in data:
    if search1 in sublist:
        print("there", sublist)
        if search2 in sublist:
            print("there", sublist)
            found = True
    if(found==False):
        print("not there")
        print(data) 
if(found==False):
    print("not there")
    print(data)
我得到的输出是:
there [4,3] #I only want this sublist, and only once. 
there [4,3]
there [6,3] #I don't want this sublist. 
干杯! 5813