【发布时间】:2020-09-02 02:24:07
【问题描述】:
我有一个单词列表,应该与字典中的某些键匹配。如何返回匹配的键及其值?
terms = ['history', 'patient', 'anotherTerm', ...]
dictionary = {'history': ['str1', 'str2', 'str3'],
'clinical': ['str1', 'str2', 'str3'],
'patient': ['str1', 'str2', 'str3'], ....}
我执行了打印匹配键的循环,但我不确定如何打印键的值。如何确保返回键及其值列表?
for c in terms:
for k in concepts.keys():
if c == k:
print("key:", k) #value?
【问题讨论】:
-
if term in concepts: ...
标签: python dictionary for-loop key-value