检查集合中是否存在列表的任何元素的pythonic方法
pythonic way to check if any elements of a list is present in a set
正在尝试找到一种方法来检查以下内容:
approved_countries = ['Germany', 'France']
我们有5套:
{'Germany'}
{'Germany', 'France'}
{'Germany', 'France'}
{'Germany'}
{'Germany', 'Italy'}
我需要遍历 sets 并标记 list[=25] 中不存在的国家/地区的集合=] 批准的国家。
所以在这种情况下,我需要标记包含意大利的集合。
实现此目标的最 pythonic 方法是什么?
for index,row in enumerate(dataset):
if any([i not in approved_countries for i in row)):
print("Row {} is bad".format(index))
正在尝试找到一种方法来检查以下内容:
approved_countries = ['Germany', 'France']
我们有5套:
{'Germany'}
{'Germany', 'France'}
{'Germany', 'France'}
{'Germany'}
{'Germany', 'Italy'}
我需要遍历 sets 并标记 list[=25] 中不存在的国家/地区的集合=] 批准的国家。
所以在这种情况下,我需要标记包含意大利的集合。
实现此目标的最 pythonic 方法是什么?
for index,row in enumerate(dataset):
if any([i not in approved_countries for i in row)):
print("Row {} is bad".format(index))