[英]Find all values in a list which match in a dictionary?
lets say I have the following dictionary假设我有以下字典
dict1= {"a":[1,2,3],"b":[2,3,4]}
how would I make it so the output is:我将如何做到,所以 output 是:
[2,3]
where the values match in a dictionary.其中值在字典中匹配。
you can refer to my code bellow:你可以参考我的代码如下:
arr1 = d['a']
arr2 = d['b']
arrResult = []
for i in arr1:
if arr2.__contains__(i):
arrResult.append(i)
print(arrResult)
and here is the result: [2, 3]
结果如下:
[2, 3]
More advanced you can use:您可以使用更高级的:
x = set.intersection(*map(set, d.values()))
print(x)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.