我有字典的字典。我希望有一个功能,如果arguement就像是匹配的将返回所有的细节,Python中的字典的字典的迭代字典
identifiers = {
'42566431313931326462642d3533656132352033': {
'name': 'topleft',
'subid': {
'a3e54b84450000': {
'name': 'north'
}
}
},
'0942378098093': {
'name': 'topright',
'subid': {
'4b840000100000000000': {
'name': 'north'
}
}
},
'4256643131ra98892389': {
'name': 'bottomleft',
'subid': {
'a3e54b840000100000000000': {
'name': 'west'
}
}
}
}
def getdetails(p):
# p could be key of dict or dict of dict
for key in identifiers:
if key == p:
return identifiers[key]
else:
if p in identifiers[key]['subid']:
return identifiers[key]['subid'][p]
我想知道是否有高贵的方式来做到这一点(可以是使用地图和lambda)?
什么是'D',为什么你覆盖'key'? – thefourtheye
'identifier'与'identifiers'不同吗? – thefourtheye
提示:在Python中使用'//'注释会引发语法错误 –