Q:

convert a piece of code from ruby into python

I have a piece of code that it was written in Ruby. I want to convert it into Python. 
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 << min + ((max-min)/((2.0**bits_per_param.to_f)-1.0)) * sum
  end
  return vector
end

I convert it like below. I need help in converting param.
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

param has not been converted correctly. 
ps. here is the code of the iif function:
def iif(condition, true_part, false_part):
    return (condition and [true_part] or [false_part])[0]

A:

I think I could solve my problem partially. The code in python would be like below.
def decode(bitstring, search_space, bits_per_param):
vector = []
for i, bounds in enumerate(search_space):
    off, sum = i * bits_per_param, 0.0
    param = (bitstring[off:(off+bits_per_param)])[::-1]
    for j in xrange(0, len(param)):
        if param[j].__str__() == '1':
            sum += 1.0 * (2**float(j))
        else:
            sum += 0.0 * (2**float(j))
    min, max = bounds
    vector.append(min + ((max - min) / ((2.0 ** bits_per_param) - 1.0)) * sum)
return vector

