我正在研究cs50的pset6,DNA,我想读一个csv文件,看起来像这样:
name,AGATC,AATG,TATC
Alice,2,8,3
Bob,4,1,5
Charlie,3,2,5
我要创建的是一个嵌套字典,如下所示:
data_dict = {
"Alice" : {
"AGATC" : 2,
"AATG" : 8,
"TATC" : 3
},
"Bob" : {
"AGATC" : 4,
"AATG" : 1,
"TATC" : 5
},
"Charlie" : {
"AGATC" : 3,
"AATG" : 2,
"TATC" : 5
}
}
所以我想用这个:
with open(argv[1]) as data_file:
for i in data_file:
(或另一个变体)循环通过csv
文件和append
到字典,添加所有值,这样我就有了一个以后可以访问的数据库
使用简单的文件读取
输出
您应该使用python的csv.DictReader模块
相关问题 更多 >
编程相关推荐