import re

m = """
0 1 2 3 4 5
1 0 1 2 3 4
2 1 1 2 3 4
"""
repl = 'bip'

print (re.sub(r'\n', '\n{} ', m, len(repl)).format(*list(repl)))