我有两个清单:
list1 = [1,2,3,4,5]
list2 = [9,2,6,5,8]
我试图找到两个数组中匹配的值和匹配值的最小值。
for x in list1:
for i in list2:
if (x == i):
z=x
print min(z)
我收到错误
答案 0 :(得分:5)
list1 = [1,2,3,4,5]
list2 = [9,2,6,5,8]
list3 = set(list1).intersection(list2)
print(list3) # {2, 5}
print(min(list3)) # 2
答案 1 :(得分:3)
min(set(list1) & set(list2), default=None)