How to replace a comma

Peter Otten __peter__ at web.de
Mon Dec 18 08:14:05 EST 2006


Lad wrote:

> In a text I need to
> add a blank(space) after a comma but only if there was no blank(space)
> after the comman
> If there was a blank(space), no change is made.

>>> s = "alpha, beta,gamma,  delta"
>>> ", ".join(t.replace(",", ", ") for t in s.split(", "))
'alpha, beta, gamma,  delta'

Peter



More information about the Python-list mailing list