find all dictionaries that each have an indeterminate number of defined keys
<p>I have information about a bunch of different items. Each item has its own dictionary filled with information about that item, and I have a larger dictionary in which each item is stored. I do not, however, have all the same information for each item. For instance, let's say my items are fruit. Then the structure looks like:</p>

<pre><code>fruit = {}
fruit['apple'] = {'color': 'red', 'origin': 'Washington'}
fruit['banana'] = {'color': 'yellow'}
fruit['orange'] = {'color': 'orange', 'origin': 'Florida'}
</code></pre>

<p>If I want to find origin of each fruit for which it has been defined, I am doing the following:</p>

<pre><code>fruits, origins = zip(* [(f, fruit[f]['origin']) for f in fruit.keys() if 'origin' in fruit[f]])
</code></pre>

<p>That works fine. It starts getting ugly once I want to find every fruit that has both a color and origin defined. </p>

<pre><code>fruits, origins, colors = zip(* [(f, fruit[f]['origin'], fruit[f]['color']) for f in fruit.keys() if 'origin' in fruit[f] and 'color' in fruit[f]])
</code></pre>

<p>What I would like to do is be able to write a general function that will perform this action for any number of specified keys. That is, I could call some function called "defined" that would take a dictionary of dictionaries, and a key or list of keys within a sub-dictionary, and return all of the sub-dictionaries that have definitions for each of those keys, as well as the values for each key.</p>

<pre><code>fruits, origins = defined(fruit, ['origin'])
fruits, origins, colors = defined(fruit, ['origin', 'color'])
</code></pre>

<p>I've looked at a variety of existing threads with questions about getting key/value pairs out of or in to dictionaries, but I have not found anything that looks right. Is there a reasonably straightforward way to generalize this? </p>

<p>Or, if people also want to tell me that I should be organizing my data in entirely different way, I would also welcome that. I initially settled on a dictionary of dictionaries because of the wide range of information available for each item. For instance, some sub-dictionaries have tens of entries with information, and some items only have a few entries (that is, the 'apple' dictionary has a lot of information, but I do not have much stored in 'kumquat'). </p>
