a = {
'brand' : 'toyota'
'model' : 'corolla'
'specs' : ['motor', 'cil', 'hp']
'des_spec' : [2.4, 4, 187]
}
t = 0 # Counter
for spec in a["specs"]: # Loop over the specs
a[spec] = des_spec[t] # Insert into dictionary, key from spec, value from des_spec
t += 1 # Up the counter
使用
dict.pop
和zip
Ex:
如果你不需要它灵活的其他情况下,你可以做
相关问题 更多 >
编程相关推荐