Extract values by key from a nested dictionary(从嵌套字典中按键提取值)
问题描述
给定这个嵌套字典,我如何使用 for 循环打印所有电话"值?
Given this nested dictionary, how could I print all the "phone" values using a for loop?
people = {
'Alice': {
'phone': '2341',
'addr': '87 Eastlake Court'
},
'Beth': {
'phone': '9102',
'addr': '563 Hartford Drive'
},
'Randy': {
'phone': '4563',
'addr': '93 SW 43rd'
}
推荐答案
for d in people.values():
print d['phone']
这篇关于从嵌套字典中按键提取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!