title: convert a piece of code from ruby into python
body: <p>I have a piece of code that it was written in Ruby. I want to convert it into Python. </p>
  
  <pre class="lang-rb prettyprint-override"><code>def decode(bitstring, search_space, bits_per_param)
    vector = []
    search_space.each_with_index do |bounds, i|
      off, sum = i*bits_per_param, 0.0
      param = bitstring[off...(off+bits_per_param)].reverse
      param.size.times do |j|
        sum += ((param[j].chr=='1') ? 1.0 : 0.0) * (2.0 ** j.to_f)
      end
      min, max = bounds
      vector &lt;&lt; min + ((max-min)/((2.0**bits_per_param.to_f)-1.0)) * sum
    end
    return vector
  end
  </code></pre>
  
  <p>I convert it like below. I need help in converting <code>param</code>.</p>
  
  <pre class="lang-py prettyprint-override"><code>def decode(bitstring, search_space, bits_per_param):
      vector = []
      for i, bounds in enumerate(search_space):
          sum = i * bits_per_param
  
  
  
      for j in xrange(0, len(param)):
          sum += iif(param[j] == '1', '0', '1') * (2 ** j), param[j]
      min, max = bounds
      vector = min + ((max - min) / ((2.0 ** bits_per_param) - 1.0)) * sum
      return vector
  </code></pre>
  
  <p><code>param</code> has not been converted correctly. </p>
  
  <p>ps. here is the code of the <em>iif</em> function:</p>
  
  <pre><code>def iif(condition, true_part, false_part):
      return (condition and [true_part] or [false_part])[0]
  </code></pre>