person_0 = {'surname': 'kaihu', 'given_name': 'biangeng', 'age':'18','city': 'kaixiaobian'} person_1 = {'surname': 'shebaoka', 'given_name': 'chongzuoka', 'age':'19', 'city': 'ka'} person_2 = {'surname': 'gongjijin', 'given_name': 'guiji', 'age':'20', 'city': 'tiqu'} persons = [person_2,person_1,person_0] for person in persons: print(person) pet_0 = {'type': 'kaihu','owner':'lixueqing',} pet_1 = {'type': 'biangeng', 'owner':'hounaonao'} pet_2 = {'type': 'xiaohu', 'owner':'xiaotiantian'} pets = [[pet_2,pet_1,pet_0]] for pet in pets: print(pet) favorite_places = { 'lixueqing' :['kaihu','xiaohu'], 'hounaonao' :['biangeng'], 'xiaotiantian':['shebaoka','chongzuoka','tunka'], } for person, favorite_place in favorite_places.items(): print(f"{person.title()}'s favorite place is:") for place in favorite_place: print(f"\t{place.title()}") favorite_numbers = { 'kaihu':[1,2], 'xiaohu':[2,3,4], 'biangeng':[5], 'shebaoka':[4,7,8], 'chongzuoka':[5,7,9,0], } for person, numbers in favorite_numbers.items(): print(f"{person.title()}'s favorite number is:") for number in numbers: print(number) cities = { 'kaihu': { 'country': 'china', 'population': 100, 'fact': 'kaihushu', }, 'biangeng':{ 'country': 'us', 'population': 200, 'fact': 'biangengshu', }, 'xiaohu': { 'country': 'uk', 'population': 300, 'fact': 'xiaohushu', } } for city, city_info in cities.items(): print(f"City: {city}") country = f"{city_info['country']}" population = f"{city_info['population']}" fact = f"{city_info['fact']}" print(f"{city.title()},located in {country.title()}.There is {population} people in this city,happened {fact.upper()}")
关于两层嵌套可以用在有关用于属性的方面,例如万叶的攻伤暴精通等属性以及风伤加成。通过词典的二级嵌套我可以创建出来一个RPG人物的属性。更复杂的可以存在三层嵌套,但是不如另外创建一个二级嵌套系统然后实施互相影响。