title: How to implement efficient filtering logic in Python?
body: <p>I am trying to create a program that stores</p>
  
  <ol>
  <li>Fruit Name</li>
  <li>Fruit Type</li>
  <li>Fruit Color</li>
  <li>Fruit Size</li>
  </ol>
  
  <p>and show them back to the user upon request. The user will be given pre-defined choices to select from. Something like this:</p>
  
  <p><img src="https://i.stack.imgur.com/7IWPd.png" alt="Enter image description here"></p>
  
  <p>My database table will be like this:</p>
  
  <p><img src="https://i.stack.imgur.com/zR6Ia.png" alt="Enter image description here"></p>
  
  <p>Now, I am trying to implement a filter function that lets the user select </p>
  
  <ul>
  <li>Fruit Type</li>
  <li>Fruit Color</li>
  <li>Fruit Size</li>
  </ul>
  
  <p>And it will give out all the <code>Fruit Names</code> that have the above properties. But now, I have an additional option, "All".</p>
  
  <p><img src="https://i.stack.imgur.com/fnkRI.png" alt="Enter image description here"></p>
  
  <p>Assuming that I have already queried out the data for all the fruits and stored them in dictionary like this:</p>
  
  <pre><code>myfruits = { 'apple':('fleshy','red','medium'),
              'orange':('fleshy','orange','medium'),
               'peanut':('dry','red','small'),...}
  </code></pre>
  
  <p>How do I get the list of fruit names that has the three properties that the user selected? (For example, if the user selected 'fleshy' type , 'All' color, 'All' size -- it should return <code>['apple','orange']</code>.)</p>
  
  <p>I have thought of using <code>if</code> statement, but as the number of properties grow, I would have to write so many lines of <code>if</code> and <code>else</code> which I don't think is feasible.</p>
  
  <p>I am using Python 2.7 with <a href="https://en.wikipedia.org/wiki/PyQt" rel="nofollow noreferrer">PyQt</a> 4 and the <a href="http://en.wikipedia.org/wiki/SQLite" rel="nofollow noreferrer">SQLite</a> 3 database on Windows&nbsp;XP SP3 32-bit.</p>