嵌套

# 6-8
qinhui = {'breed': 'dog', 'master': 'yuefei'}
yansong = {'breed': 'pig', 'master': 'xujie'}
gaoqiu = {'breed': 'tortoise', 'master': 'linchong'}

pets = [qinhui, yansong, gaoqiu]

for pet in pets:
    print(pet)

# 6-9
favorite_places = {
    'jian': ['huangshan', 'wuyuan', 'xizang'],
    'yang': ['guilin', 'dikengyuan', 'chayeshan'],
    'haozi': ['jiaozuo', 'yuntaishan', 'lvzumiao'],
}

for name, places in favorite_places.items():
    print(name.title() + " likes: ")
    for place in places:
        print("\t" + place.title())

# 6-11
cities = {
    'henan': {
        'country': 'china',
        'population': '95.32 million',
        'fact': 'There are too many people!',
    },

    'tokyo': {
    'country': 'japan',
    'population': '13.50 million',
    'fact': 'There are many chusheng in Japan!',
    },

    'taiwan': {
        'country': 'china',
        'population': '23.49 million',
        'fact': 'Taiwan is an inherent part of China!',
    },
}

for city, city_info in cities.items():
    print("\nCity: " + city.title())
    print("\tCountry: " + city_info['country'])
    print("\tPopulation: " + city_info['population'])
    print("\tFact: " + city_info['fact'])
{'breed': 'dog', 'master': 'yuefei'}
{'breed': 'pig', 'master': 'xujie'}
{'breed': 'tortoise', 'master': 'linchong'}
Jian likes: 
    Huangshan
    Wuyuan
    Xizang
Yang likes: 
    Guilin
    Dikengyuan
    Chayeshan
Haozi likes: 
    Jiaozuo
    Yuntaishan
    Lvzumiao

City: Henan
    Country: china
    Population: 95.32 million
    Fact: There are too many people!

City: Tokyo
    Country: japan
    Population: 13.50 million
    Fact: There are many chusheng in Japan!

City: Taiwan
    Country: china
    Population: 23.49 million
    Fact: Taiwan is an inherent part of China!
    原文作者:庵下桃花仙
    原文地址: https://www.jianshu.com/p/4c7e833f6274
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞