0
我有一個嵌套的,責令建在Python 3詞典它看起來像這樣:Python 3中嵌套的有序字典鍵訪問
coefFieldDict = OrderedDict([(('AC_Type',),
OrderedDict([('BADA_code', 0), ('n_engine', 1), ('eng_type', 2), 'wake_cate', 3)])),
(('Mass',), OrderedDic([('m_ref', 4), ('m_min', 5), ('m_max', 6), ('m_pyld', 7), ('G_w', 8), ('unused', 9)]))
(('Flight_Env',), OrderedDict([('V_MO', 10), ('M_MO', 11), ('h_MO', 12), ('h_max', 13), ('G_t', 14), ('unused', 15)]))], ...)
現在,我想的密鑰列表頂部的水平,這是我獲得搭配:
outerKeys = list(coefFieldDict.keys())
這給我:
[('AC_Type',),
('Mass',),
('Flight_Env',),
('Aero',),
('Thrust',),
('Fuel',),
('Ground',)]
併爲關鍵之一的一個例子,我有:
list(coefFieldDict.keys())[1][0]
Out[104]: 'Mass'
現在,在使用這種有效的鑰匙插入orderedDict( 'coefFieldDict'),我收到此錯誤:
Traceback (most recent call last):
File "<ipython-input-107-61bab1ad7886>", line 1, in <module>
coefFieldDict['Mass']
KeyError: 'Mass'
我做錯了嗎?
請正確格式示例詞典。 – ospahiu