title: Convert string to conditional and statements
body: <p>I have string variable like:</p>
  
  <pre><code>s = 'apple&lt;3,meizu&gt;5;samsung=9,foo=bar'
  </code></pre>
  
  <p>and a of dictionaries like:</p>
  
  <pre><code> D = [  
          {'apple': 9, 'meizu': 12, 'samsung': 90, 'oppo': 12', foo': 'bar'}, 
          {'apple': 91, 'meizu': 22, 'samsung': 72, 'foo': 'test'},
           ...
       ]
  </code></pre>
  
  <p>I need to convert <code>s</code> to  </p>
  
  <pre><code>"if apple &lt; 3 and (meizu &gt; 5 or samsung==9) and foo=='bar'"  # (semicolon is OR, comma is AND)
  </code></pre>
  
  <p>and check each element of list <code>D</code> with this conditional, like:</p>
  
  <pre><code>for i in D:
    if i['apple']&lt;3 and (i['meizu']&gt;5 or i['samsung']==9) and i['foo']=='bar':
       print ('ok')
  </code></pre>
  
  <p>I don't understand how to implement it. I tried <code>eval(s)</code>, but I'm not sure that is a good solution.</p>