【发布时间】:2020-07-01 10:32:40
【问题描述】:
我有一个这样的字典
D={'Physician procedure note':a,'Dentistry Procedure note':b,'Podiatry Procedure note':c}
我想在上面的字典中用关键字“程序报告”搜索这本字典。我想找出字典中最近的键附近并提取值。
I have used this approach
search_key = 'Procedure report'
# Using items() + list comprehension
# Substring Key match in dictionary
result = [val for key, val in D.items() if search_key in key]
# printing result
print("Values for substring keys : " + str(result))
我的列表是空的。我该如何改变这个。
【问题讨论】:
-
预期输出是什么?
-
如果我将“程序报告”作为匹配键。我想检索上面字典“医师程序笔记”、“牙科程序笔记”、“足病程序笔记”中的所有键
-
res字典是什么?您的D字典不包含您的 search_key -
两者都一样
-
字典中没有一个键包含文本
Procedure report
标签: python-3.x string dictionary