我有一个类似以下的字典:
d = {"employee": ['PER', 'ORG']}
我有一个从特定实体列表
中提取出来的标签 ('PER', 'ORG',....)
列表。
for t in entities_with_tag: # it includes words with a tag such as: [PER(['Bill']), ORG(['Microsoft']),
f = t.tag # this extract only tag like: {'PER, ORG'}
s =str(f)
q.add(s)
现在我想要做的是,如果
q
中包含{'PER, ORG'}
,并且它与d.values()
匹配,那么它应该给我{'PER, ORG'}
的keys
,即'employee'
。我尝试了这个方法但不起作用。for x in q:
if str(x) in str(d.values()):
print(d.keys()) # this print all the keys of dict.
"employee": ["PER", "LOC"]
和"Located": ["ORG", "LOC"]
。由于"LOC"
出现在两个键中,它会返回两个键,但我希望只返回当两个值都相同时的结果,而不是其中一个值。请问该如何解决这个问题? - Zia