已知字典中某几个key,取每个key对应的值

'''
https://www.cnblogs.com/xiazhenyu/
*** 学而思之、思而记之、记而习之 ***
'''

dict1={
"attr":{
"httpClient":{
"hasData":"false",
"cacheKey":"8888rrr"
}
}
}

# print(dict1['attr']['httpClient']['cacheKey'])

a="attr,httpClient,cacheKey"
res=a.split(',')
# print(res[0])
# print(dict1[res[0]][res[1]][res[2]])

nums=2
if nums == 0:
print(dict1[res[0]])
elif nums == 1:
print(dict1[res[0]][res[1]])
elif nums == 2:
print(dict1[res[0]][res[1]][res[2]])

#返回结果:8888rrr

原文地址:https://www.cnblogs.com/xiazhenyu/p/13731739.html