def setDictProperty(phone='', age=0, sex=''):
propertyDict={}
propertyDict['phone']=phone
propertyDict['age']=age
propertyDict['sex']=sex
return propertyDict
propertyDict={}
propertyDict['phone']=phone
propertyDict['age']=age
propertyDict['sex']=sex
return propertyDict
liqipropertyDict={}
wangjuanpropertyDict={}
liyutongpropertyDict={}
wangjuanpropertyDict={}
liyutongpropertyDict={}
aDict={'liqi': liqipropertyDict, 'wangjuan': wangjuanpropertyDict, 'liyutong': liyutongpropertyDict}
if 'liqi' in aDict.keys():
aDict['liqi']=setDictProperty('137xxxxx256', 31, 'male')
if 'wangjuan' in aDict.keys():
aDict['wangjuan']=setDictProperty('132xxxxx935', 28, 'female')
if 'liyutong' in aDict.keys():
aDict['liyutong']=setDictProperty(0, 1, 'female')
aDict['liqi']=setDictProperty('137xxxxx256', 31, 'male')
if 'wangjuan' in aDict.keys():
aDict['wangjuan']=setDictProperty('132xxxxx935', 28, 'female')
if 'liyutong' in aDict.keys():
aDict['liyutong']=setDictProperty(0, 1, 'female')
print aDict
for key in aDict.iterkeys():
print '*' * 50
for k in aDict[key].iterkeys():
print "%s: %s" % (k, aDict[key][k])
print '*' * 50
for k in aDict[key].iterkeys():
print "%s: %s" % (k, aDict[key][k])
运行结果:
{'liyutong': {'phone': 0, 'age': 1, 'sex': 'female'}, 'wangjuan': {'phone': '132xxxxx935', 'age': 28, 'sex': 'female'}, 'liqi': {'phone': '137xxxxx256', 'age': 31, 'sex': 'male'}}
**************************************************
phone: 0
age: 1
sex: female
**************************************************
phone: 132xxxxx935
age: 28
sex: female
**************************************************
phone: 137xxxxx256
age: 31
sex: male
**************************************************
phone: 0
age: 1
sex: female
**************************************************
phone: 132xxxxx935
age: 28
sex: female
**************************************************
phone: 137xxxxx256
age: 31
sex: male