Replace space character between two numbers

python, replace, string

Solution

There are several ways to do it (sorry, Zen of Python). Which one to use depends on your input:

>>> s = "15.30 396.90"
>>> ",".join(s.split())
'15.30,396.90'
>>> s.replace(" ", ",")
'15.30,396.90'

or, using `re`, for example, this way:

>>> import re
>>> re.sub("(\d+)\s+(\d+)", r"\1,\2", s)
'15.30,396.90'

Problem

I need to replace space with comma between two numbers ``` 15.30 396.90 => 15.30,396.90 ``` In PHP this is used: ``` '/(?<=\d)\s+(?=\d)/', ',' ``` How to do it in Python?

Original source