我是Python新手。 我有一个元组 元组=(3,4,5) 我有一份清单。 列表= [3,5]
我希望输出为4,因为[3,4,5]中存在[3,5] 我如何使用Python做到这一点?
答案 0 :(得分:2)
您可以将迭代变换为集合,然后执行集合差异。
.find({
'result.extractorData.data[0].group[0].address': {
$exists: true
}
});
答案 1 :(得分:1)
my_tuple = (3, 4, 5)
my_list = [3, 5]
# Check to see whether each item in your list is also in the tuple.
if all(item in my_tuple for item in my_list):
# Convert both to sets and print the difference.
print set(my_tuple) - set(my_list)
输出:
set([4])