python中字典的嵌套:在字典中存储列表

又字典列表,也有列表字典,顾名思义,列表字典就是字典的value值是列表的数据类型,我们通过字典的索引得到一个列表,然后再通过对列表的操作进行处理。只要把读取后的字典value值存在一个变量里面,这个变量就可以看成是普通的列表了,可以通过以下程序来进行演示:

favorite_places={
	"wangchenou":	["dayuan","dongzhou"],
	"lixiang"	:	["chunjiang","wanshi"],
	"heqizheng"	:	["fuyang","hengchai","chunjian"]
}

for name in favorite_places:
	print(name+"'s favorite places are:")
	for place in favorite_places[name]:
		print(place)
	print("****************************")

运行之后的演示结果如下所示:

wangchenou's favorite places are:
dayuan
dongzhou
****************************
lixiang's favorite places are:
chunjiang
wanshi
****************************
heqizheng's favorite places are:
fuyang
hengchai
chunjian
****************************
[Finished in 0.5s]

你可能感兴趣的:(python基础数据类型)