title: How to count all elements in a nested dictionary?
body: <p>How do I count the number of subelements in a nested dictionary in the most efficient manner possible?  The len() function doesn't work as I initially expected it to:</p>
  
  <pre><code>&gt;&gt;&gt; food_colors = {'fruit': {'orange': 'orange', 'apple': 'red', 'banana': 'yellow'}, 'vegetables': {'lettuce': 'green', 'beet': 'red', 'pumpkin': 'orange'}}
  &gt;&gt;&gt; len(food_colors)
  2
  &gt;&gt;&gt;
  </code></pre>
  
  <p>What if I actually want to count the number of subelements? (e.g., expected result to be "6")  Is there a better way to do this rather than looping through each element and summing the qty of subelements?  In this particular application, I have about five million subelements to count and every clock cycle counts.</p>