['*a*', '*b*', '*c*', '*d*', '*f*','*g*']
['11', '22', '33', '44', '', '55']
['66', '77', '88', '', '99', '10']
['23', '24', 'sac', 'cfg', 'dfg', '']
必要把在字典爲:其被試過如上所示如何將多個列表轉換爲Python中的字典?
import csv
csvFile = csv.reader(open("sach.csv", "rb"))
for row in csvFile:
print row
代碼, 行的輸出被如上所示:
{a : ('11','66','23'),b : ('22','77','24'),c : ('33','88','sac'),d :('44','','cfg')}
行被從CSV文件中讀取其中有許多名單。 請幫我把它放在字典格式,如上所示。通過在reader
對象通過與在CSV行*
參數Python會循環
with open("sach.csv", "rb") as csv_infile:
reader = csv.reader(csv_infile)
yourdict = {r[0].replace('*', ''): r[1:] for r in zip(*reader)}
的zip()
function爲你做配對,並通過每行作爲一個單獨的參數zip()
:
在你的字典裏,你需要把鑰匙變成'a','a''還是''a *''? –