如何在Python3中搜索两个项目的列表

时间:2017-12-01 22:04:04

标签: python python-3.x list

我需要一些帮助来搜索两个不同数据的单个列表,如何做到这一点,如果这样,如果这两个数据将输出值,那么就找到了。

3 个答案:

答案 0 :(得分:3)

您可以使用几个in运算符:

def both_in_list(lst, a, b):
    return a in lst and b in lst

答案 1 :(得分:2)

list1 = [1,2,3,4,5,6]

list2 = [6,7,8,9,10]

if (6 in list1) and (6 in list2):

    print("The elements that you're looking for is there!")

else:

    print("One of the lists does not that the element you're looking for!")

答案 2 :(得分:1)

使用了几个in运算符来执行此操作。

    list = [2,4,8,14,16]
    if 2 in list and 4 in list
        print("2 and 4 are found in this list.")
    else:
        print("These numbers are not found in this list.")