a={'a':{'b':{'c':{'d':'e'}},'f':'g'},'h':'i'}

def show(myMap):

for str in myMap.keys():
secondDict=myMap[str]
print str
if type(myMap[str]).__name__=='dict':
for key in secondDict.keys():
if type(secondDict[key]).__name__=='dict':
print key
show(secondDict[key])
else:
print key
print secondDict[key]
else:
print myMap[str]

show(a)

通过递归来实现遍历字典中的所有元素。效率可能比较低。

相关文章:

  • 2021-04-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-29
  • 2018-04-26
  • 2021-06-29
  • 2022-12-23
猜你喜欢
  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2022-12-23
  • 2021-06-02
相关资源
相似解决方案