title: Python Programming: how to eval values from dictionary?
body: <p>Given string </p>
  
  <pre><code>str=" dept_id == CS1  and  student_count &gt; 75 " 
  </code></pre>
  
  <p>Dictionary   </p>
  
  <pre><code>dict = {'dept_id': 'CS1' ,'student_count': 95 }
  </code></pre>
  
  <p>We need to substitute values from dict in string and evaluate</p>
  
  <pre><code>eval (str)
  </code></pre>
  
  <p>code below works for all integer cases :</p>
  
  <pre><code>for item in dict.items():
  k , v  = item
  if s.find(k) &gt; -1:
   k=str(k)
   s=s.replace(k, str(v),1)
   print "replaced",s
  
  print eval(s)
  </code></pre>
  
  <p>Is there any other way to approach this problem?</p>