python 2 字典的基本使用
dicVisit={}
if not dicVisit.has_key(visitKey):#不存在 diaSet = set() diaSet.add(diagnoseContent) dicVisit[visitKey]=diaSet #print ("new==="+visitKey + "-----"+diagnoseContent) else: #取出字典中对应元素值,是个 set,并将诊断加进去 originalDiaSet=dicVisit[visitKey] # for item in originalDiaSet: # print item originalDiaSet.add(diagnoseContent)
遍历:
for key in dicVisitList.keys(): valueDic = dicVisitList[key] jsonData.append(valueDic) print(valueDic)