使用Python列表中的元素更新字典的值

使用Python列表中的元素更新字典的值,python,dictionary,Python,Dictionary,我创建了一个列表和一个字典来计算氨基酸频率 我想用列表中的值替换字典中的值 那么比如说, 我现在拥有的是 L1=[0.0429,0.0071,0.05,0.0929,0.0429,0.0143,0.0071,0.0429,0.0929,0.1143,0.0643,0.0643,0.05,0.0286,0.0286,0.0643,0.0857,0.0714,0.0143,0.0214] 及 D1=OrderedDict([('A',6),('C',1),('D',7),('E',13),('F',

我创建了一个列表和一个字典来计算氨基酸频率

我想用列表中的值替换字典中的值

那么比如说,

我现在拥有的是

L1=[0.0429,0.0071,0.05,0.0929,0.0429,0.0143,0.0071,0.0429,0.0929,0.1143,0.0643,0.0643,0.05,0.0286,0.0286,0.0643,0.0857,0.0714,0.0143,0.0214]

D1=OrderedDict([('A',6),('C',1),('D',7),('E',13),('F',6),('G',2),('H',1),('I',6),('K',13),('L',16),('M',9),('p',7),('Q',4),('R',4),('S',9),('T',12),('V',10),('W',2),('Y',3)

我想将
D1
中的每个值替换为
L1
中的值。 例如,我想要
([('A',0.0429),('C',0.0071)…
等等

这是创建列表(
L1
)和字典(
D1
)的代码


非常简单,因为您已经按顺序排列了值和键

for val, key in zip(L1, D1):
    D1[key] = val
似乎您应该就地执行此操作,因为您没有添加或删除元素

total = float(um(Counter(seq_record.seq).values()))
for key,val in sorted_dict.items():
    newval = round(val/total, 4)
    sorted_dict[key] = newval

谢谢这正是我想要的,
total = float(um(Counter(seq_record.seq).values()))
for key,val in sorted_dict.items():
    newval = round(val/total, 4)
    sorted_dict[key] = newval