#### Check if dictionary contains at least one specific value out of a list

``````d = {'1': 'one', '3': 'three', '2': 'two', '5': 'five', '4': 'four'}

if 'six' in d.values() or 'eight' in d.values() or 'ten' in d.values() or 'fifteen' in d.values():
# do something
else:
# do something else
``````

``````targets = ['six', 'eight', 'ten', 'fifteen']
d = {'1': 'one', '3': 'three', '2': 'two', '5': 'five', '4': 'four'}

for t in targets:
if t in d.values():
# do something
break  # to ensure the thing isn't triggered multiple times
else:
# do something else
break  # to ensure the thing isn't triggered multiple times
``````

3 个回复

``````if any(t in d.values() for t in targets):
pass
else:
pass
``````

``````values = set(d.values())

if any(t in values for t in targets):
# ...
``````

``````d = {'1': 'one', '3': 'three', '2': 'two', '5': 'five', '4': 'four'}
targets = ['four', 'nine']

if set(d.values()) & set(targets):
print('overlap')
else:
print('no overlap')
``````

``````if {"six","eight","ten","fifteen"}.isdisjoint(d.values()):
print("None of the values are present")
else:
print("At least one of the values is present")
``````
1 检查是否至少一个列表包含特定元素

2021-01-10 20:11:42 4 72   list
2 检查字符串是否包含列表中的至少一个字符串

3 检查列表是否至少包含另一个 - 枚举

4 如何获取字典键，其值至少包含另一个列表中的一项？

6 检查列表中是否存在具有特定值的字典

7 检查一个字符串是否在单词列表R中至少包含n个单词

2017-05-17 11:37:23 1 282   r/ contain
8 检查一个向量是否包含来自另一个向量的至少一个值

2016-04-13 14:43:47 3 625   clojure
9 找出哪个列表包含字典中的值

10 检查字典值是否包含列表项