其他分享
首页 > 其他分享> > 已知字典中某几个key,取每个key对应的值

已知字典中某几个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

标签:cacheKey,dict1,nums,res,已知,key,print,httpClient,字典
来源: https://www.cnblogs.com/xiazhenyu/p/13731739.html