我正在尝试创建一个 for 循环来为已建立的字典中的键添加值。但是,我不断获得最后一个值而不是所有值。我做错了什么?
我现在的字典看起来像:
growth_dict = dict.fromkeys(conc[1:9], '')
growth_dict = {'100 ug/ml': '', '12.5 ug/ml': '', '50 ug/ml': '',
'0 ug/ml': '', '6.25 ug/ml': '', '25 ug/ml': '', '3.125 ug/ml': '',
'1.5625 ug/ml': ''}
cols_list = numpy.loadtxt(fn, skiprows=1, usecols=range(1,9), unpack=True)
numer = (0.301)*960 #numerator
for i in cols_list:
N = i[-1]
No = i[0]
denom = (math.log(N/No)) #denominator
g = numer/denom
当我运行程序并输入“growth_dict”时,它会返回我的字典,其中只有最后一个值作为键:
growth_dict = {'100 ug/ml': 131.78785283808514, '12.5 ug/ml': 131.78785283808514,
'50 ug/ml': 131.78785283808514, '0 ug/ml': 131.78785283808514,
'6.25 ug/ml': 131.78785283808514, '25 ug/ml': 131.78785283808514,
'3.125 ug/ml': 131.78785283808514, '1.5625 ug/ml': 131.78785283808514}