title: Python: Tuples/dictionaries as keys, select, sort
body: <p>Suppose I have quantities of fruits of different colors, e.g., 24 blue bananas, 12 green apples, 0 blue strawberries and so on.
  I'd like to organize them in a data structure in Python that allows for easy selection and sorting. My idea was to put them into a dictionary with tuples as keys, e.g.,</p>
  <pre class="lang-py prettyprint-override"><code>{
      ('banana',    'blue' ): 24,
      ('apple',     'green'): 12,
      ('strawberry','blue' ): 0,
      # ...
  }
  </code></pre>
  <p>or even dictionaries, e.g.,</p>
  <pre class="lang-py prettyprint-override"><code>{
      {'fruit': 'banana',    'color': 'blue' }: 24,
      {'fruit': 'apple',     'color': 'green'}: 12,
      {'fruit': 'strawberry','color': 'blue' }: 0,
      # ...
  }
  </code></pre>
  <p>I'd like to retrieve a list of all blue fruit, or bananas of all colors, for example, or to sort this dictionary by the name of the fruit. Are there ways to do this in a clean way?</p>
  <p>It might well be that dictionaries with tuples as keys are not the <em>proper</em> way to handle this situation.</p>
  <p>All suggestions welcome!</p>