Python sorting nested dictionary list
<p>I am trying to sort a nested dictionary in Python. Right now I have a dictionary of dictionaries. I was able to sort the outer keys using sorted on the list before I started building the dictionary, but I am unable to get the inner keys sorted at this time. I've been trying to mess with the sorted API but am having problems with it.</p>

<p>Right now I have:</p>

<pre><code>myDict = {'A': {'Key3':4,'Key2':3,'Key4':2,'Key1':1},
          'B': {'Key4':1,'Key3':2,'Key2':3,'Key1':4},
          'C': {'Key1':4,'Key2':2,'Key4':1,'Key3':3}};
</code></pre>

<p>But I would like:</p>

<pre><code>myDict = {'A': {'Key1':1,'Key2':3,'Key3':4,'Key4':2},
          'B': {'Key1':4,'Key2':3,'Key2':1,'Key4':1},
          'C': {'Key1':4,'Key2':2,'Key3':3,'Key4':1}};
</code></pre>

<p>I appreciate the help!</p>

<pre><code>&gt;&gt;&gt; from collections import OrderedDict

&gt;&gt;&gt; def sortedDict(items):
...     return OrderedDict(sorted(items))

&gt;&gt;&gt; myDict = {'A': {'Key3':4,'Key2':3,'Key4':2,'Key1':1},
...           'B': {'Key4':1,'Key3':2,'Key2':3,'Key1':4},
...           'C': {'Key1':4,'Key2':2,'Key4':1,'Key3':3}}

&gt;&gt;&gt; sortedDict((key, sortedDict(value.items())) for key, value in myDict.items())
</code></pre>

python python-3.x sorting dictionary