我可以做到:
filter(lambda x: x.key1 in ["aa", "bb", "cc"], [{key1: ..., key2: ...}, {key1: ...}])
我怎么能做相反的事?
dict_items = [{key1: ..., key2: ...}, {key1: ...}]
filter(lambda x: x in ???dict_items.key1???, ["aa", "bb", "cc"])
最佳答案
假设你有两个dicts d1 = {key1: val1, key2: val2
}和d2 = {key3: val3, key4: val4}
不清楚要比较的是什么,但如果要比较键,请键入:
set.intersection(set(d1.keys()), set(d2.keys()))
对于值:
set.intersection(set(d1.values()), set(d2.values()))
关于python - 如何检查另一个数组中是否存在一个数组的键值?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36326625/