Python 3 nested ordered dictionary key access
<p>I have a nested, ordered dictionary built in Python 3.  It looks like this:</p>

<pre><code>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)]))], ...)
</code></pre>

<p>Now, I want the list of keys at the top level, which I obtain with:</p>

<pre><code>outerKeys = list(coefFieldDict.keys())
</code></pre>

<p>which give me:</p>

<pre><code>[('AC_Type',),
('Mass',),
('Flight_Env',),
('Aero',),
('Thrust',),
('Fuel',),
('Ground',)]
</code></pre>

<p>and for an example of one of the keys, I have:</p>

<pre><code>list(coefFieldDict.keys())[1][0]

Out[104]: 'Mass'
</code></pre>

<p>Now, on using this valid key into the orderedDict ('coefFieldDict'), I receive this error:</p>

<pre><code>Traceback (most recent call last):

File "&lt;ipython-input-107-61bab1ad7886&gt;", line 1, in &lt;module&gt;

coefFieldDict['Mass']

KeyError: 'Mass'
</code></pre>

<p>What I am doing wrong?</p>

<p>try <code>coefFieldDict[('Mass',)]</code></p>

<p>...Since you are using tuples (why ?) instead of strings as key</p>

python key ordereddictionary