ai_disease_profile = {'id1': 0,
'id2': 0,
'id3': 0,
'id4': 0,
'id7': 0,
'id10': 0,
'id12': 0,
'others': 0,
'all_num': 0,
'blood_area_ratio': 0,
'max_blood_area_ratio': 0}
# 字典的切片方法
targets = ['id1', 'id2', 'id3', 'id4', 'id7','id10','id12','others']
result = {key: ai_disease_profile[key] for key in ai_disease_profile.keys() if key in targets}
>>>result
{'id1': 0,
'id2': 0,
'id3': 0,
'id4': 0,
'id7': 0,
'id10': 0,
'id12': 0,
'others': 0}
字典的切片方法
最新推荐文章于 2024-05-28 19:00:00 发布