title: How to sort nested python dictionary using item's sub-value
body: <p>How to sort nested python dictionary items by their sub-values and save that dictionary items in descending order</p>
  <p>Describing dictionary:</p>
  <p>Before sorted</p>
  <pre class="lang-py prettyprint-override"><code>my_dict = {
      &quot;Bob&quot;: {&quot;Buy&quot;: 25, &quot;Sell&quot;: 33, &quot;Quantity&quot;: 100},
      &quot;Moli&quot;: {&quot;Buy&quot;: 75, &quot;Sell&quot;: 53, &quot;Quantity&quot;: 300},
      &quot;Annie&quot;: {&quot;Buy&quot;: 74, &quot;Sell&quot;: 83, &quot;Quantity&quot;: 96},
      &quot;Anna&quot;: {&quot;Buy&quot;: 55, &quot;Sell&quot;: 83, &quot;Quantity&quot;: 154},
  }
  </code></pre>
  <p>I want to sort dictionary items in descending order by their sub-values (i.e., &quot;Quantity&quot;) and the output should be like this:</p>
  <p>After sorted</p>
  <pre class="lang-py prettyprint-override"><code>my_dict={
      &quot;Moli&quot;: {&quot;Buy&quot;: 75, &quot;Sell&quot;: 53, &quot;Quantity&quot;: 300},
      &quot;Anna&quot;: {&quot;Buy&quot;: 55, &quot;Sell&quot;: 83, &quot;Quantity&quot;: 154},
      &quot;Bob&quot;: {&quot;Buy&quot;: 25, &quot;Sell&quot;: 33, &quot;Quantity&quot;: 100},
      &quot;Annie&quot;: {&quot;Buy&quot;: 74, &quot;Sell&quot;: 83, &quot;Quantity&quot;: 96},
  }
  </code></pre>
  <p>How can I do it without using any functions like:</p>
  <pre class="lang-py prettyprint-override"><code>def sort_by_quantity(dic):
      keys = sorted(dic.items(), key=lambda x: x[1]['Quantity']) # list of sorted keys
      return dict((x, y) for x, y in keys) # convert tuple back to dict
  </code></pre>
  <p><strong>or</strong></p>
  <pre class="lang-py prettyprint-override"><code>sdct = dictt.copy()
  def func(d):
      return sdct[d]['Quantity']
  dct = sorted(dictt, key=func, reverse=True)
  newDict = {i: dictt[i] for i in dct}
  print(newDict)
  </code></pre>
  <p><strong>etc...</strong></p>
  <p>The way we do sort in Pandas dataframe like:</p>
  <pre class="lang-py prettyprint-override"><code>df = df1.sort_values('Quantity', ascending=False)
  </code></pre>
  <p>I will be very grateful if someone tells me how to do this :) :) :)</p>