Replacing last comma in 'C1, C2, C3' with 'and' so that it reads'C1, C2 and C3'

Alan Green alan.green at gmail.com
Tue Jul 12 22:54:33 CEST 2005


Ric Da Force wrote:
> Hi guys,
>
> Thank you all for your input!  It was good to see so much convergence in the
> approach!

Just for divergence, you can also do this with regular expressions:

>>> import re
>>> re.sub("(.*),(.*)", r"\1 and\2", "C1, C2, C3")
'C1, C2 and C3'

Alan.




More information about the Python-list mailing list