fork download
  1. import re
  2.  
  3. line = "Float: __, string: __"
  4. values = ["float", "string"]
  5. obj = lambda:None
  6. obj.i = -1
  7.  
  8. def repl(m, count, values):
  9. count.i += 1
  10. 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"}'
  11.  
  12. newLine = re.sub(r'(_+)(\._+)?',
  13. lambda m: repl(m, obj, values),
  14. line)
  15.  
  16. print(newLine)
  17. ##Float: %2.0f, string: %2s
  18.  
Success #stdin #stdout 0.03s 9352KB
stdin
Standard input is empty
stdout
Float: %2.0f, string: %2s