import re

line = "Float: __, string: __"
values = ["float", "string"]
obj = lambda:None
obj.i = -1

def repl(m, count, values):
	count.i += 1
	return f'%{len(m.group(1))}{"." if values[count.i] == "float" else ""}{(len(m.group(2) or ".")-1) if values[count.i] == "float" else ""}{"f" if values[count.i] == "float" else "s"}'

newLine = re.sub(r'(_+)(\._+)?',
    lambda m: repl(m, obj, values),
    line)

print(newLine)      
##Float: %2.0f, string: %2s
