我有一個包含以下值的字典,其中包括航空公司代碼及其每個編號編號。將兩個列表中的值進行比較並將其更新到字典
peq = {
'sg':{'code':9, 'perror':0},
'6e':{'code':17, 'perror':0},
'g8':{'code':25, 'perror':0},
'i7':{'code':33, 'perror':0},
'9h':{'code':41, 'perror':0},
'it':{'code':49, 'perror':0},
'ic':{'code':57, 'perror':0},
'9w':{'code':65, 'perror':0},
's2':{'code':73, 'perror':0},
'ai':{'code':81, 'perror':0}
}
我有一個變量,如下所示。 perrors由錯誤代碼和ACODE的類似於其在PEQ字典
perrors = ['0', '281', '2', '16', '0', '0', '2', '0', '0', '1']
acode = [41, 65, 17, 81, 73, 57, 9, 49, 33, 25]
上述一個然後我已拉上在字典上述兩個列表中的航空公司代碼
>>> ic = dict(zip(acode,perrors))
>>> ic
{65: '281', 25: '1', 49: '0', 81: '16', 41: '0', 17: '2', 9: '2', 73: '0', 57: '0', 33: '0'}
>>>
現在我真正想解決的是更新perror提到的peq字典by比較ic代碼(左側)和peq「perror」右側的值。
對不起,如果我沒有說清楚,但概括地說我想更新在peq
字典,其在ic
字典中提到的權值提到perror
所有的值,但首先它需要做的比較是否代碼存在於peq
中,如果它確實更新了其perror
(peq
字典)與ic
值。
A)你嘗試過什麼? B)爲什麼perror從int波動到float數據類型? –