alternating string replace

cesco fd.calabrese at gmail.com
Wed Jan 9 05:34:28 EST 2008


Hi,

say I have a string like the following:
s1 = 'hi_cat_bye_dog'
and I want to replace the even '_' with ':' and the odd '_' with ','
so that I get a new string like the following:
s2 = 'hi:cat,bye:dog'
Is there a common recipe to accomplish that? I can't come up with any
solution...

Thanks in advance
Cesco



More information about the Python-list mailing list