我有字典的字典。我希望有一個功能,如果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中使用'//'註釋會引發語法錯誤 –