2.4 嵌套
#另一个例子:
favorite_languages ={
‘jean’:[‘python’,‘ruby’],
‘sarah’:[‘c’],
‘edward’:[‘ruby’,‘go’],
‘phil’:[‘python’,‘haskell’]
}
for name,languages in favorite_languages.items():
print(’\n’+name.title()+"‘s favorite languages are:")
for language in languages:
print(’\t’+language.title())
#在字典中存储字典:
users = {
‘alovelace’: {
‘first’: ‘Ada’,
‘last’: ‘Lovelace’,
‘nation’: ‘uk’,
},
'rfrost': {
'first': 'robert',
'last': 'frost',
'nation': 'US',
},
}
for user_name, user_info in users.items():
print(’\nUser name: ’ + user_name)
full_name = user_info[‘first’] + ’ ’ + user_info[‘last’]
nation = user_info[‘nation’]
print(’\tFull name: ’ + full_name.title())
print(’\tNation: ’ + nation.upper())
1.输入代码
2.输出结果