對整理資料能夠有比較好的架構
但資料卻不是有序的序列
於是可藉由list來幫忙做排序
這篇介紹list中包dictionary,及dictionary中包list的方法
1). list中包dictionary
dict1={key:a}
dict2={key:b}
list=[dict1,dict2]
or
list=[]
list.append(dict1)
2). dictionary中包list
dict={}
dict[key]=list()
dict[key].append(value)
2.1). 新增資料前先檢查有沒有key
if key not in dict:
dict[key] = list()
dict[key].append(value)
※ref:http://lucaswei.blogspot.tw/2012/05/pythondictxlist.html
沒有留言:
張貼留言