Your indices represent the digits into a binary number. So, assuming the first number in the list is always the largest power:
def to_ones_repr(powers_repr):
res = [0] * (powers_repr[0] + 1)
for power in powers_repr:
res[-(power+1)] = 1
return res
Usage:
>>> to_ones_repr([4, 3, 0])
[1, 1, 0, 0, 1]
>>> to_ones_repr([2, 1, 0])
[1, 1, 1]
Or if you want a string do this instead:
def to_ones_str_repr(powers_repr):
res = ['0'] * (powers_repr[0] + 1)
for power in powers_repr:
res[-(power+1)] = '1'
return "".join(res)
>>> to_ones_str_repr([4, 3, 0])
'11001'
>>> to_ones_str_repr([2, 1, 0])
'111'
Alternatively, calculate the number and then use the bin
function:
def to_ones_str_repr(powers_repr):
return bin(sum(2**i for i in powers_repr))
>>> to_ones_str_repr([4, 3, 0])
'0b11001'
>>> to_ones_str_repr([2, 1, 0])
'0b111'