簡單介紹 如何在list中放入dictionary
candidates=[
{"Name":"Lai","Party":"DPP","Born":"New Taipei" },
{"Name":"Hou","Party":"KMT","Born":"Chiayi"},
{"Name":"Ko","Party":"TPP","Born":"Hsinchu"},
{"Name":"Guo","Party":None,"Born":"New Taipei"}
]
for i in candidates:
print(i["Name"])
terminal 印出
Lai
Hou
Ko
Guo
--------------------------------------------------------
candidates=[
{"Name":"Lai","Party":"DPP","Born":"New Taipei" },
{"Name":"Hou","Party":"KMT","Born":"Chiayi"},
{"Name":"Ko","Party":"TPP","Born":"Hsinchu"},
{"Name":"Guo","Party":None,"Born":"New Taipei"}
]
for i in candidates:
print(i["Name"],i["Party"],i["Born"],sep=", ")
terminal 印出
Lai, DPP, New Taipei
Hou, KMT, Chiayi
Ko, TPP, Hsinchu
Guo, None, New Taipei