alternating string replace

cokofreedom at gmail.com cokofreedom at gmail.com
Fri Jan 11 04:31:14 EST 2008


evenOrOdd = True
s1, s2 = "hi_cat_bye_dog_foo_bar_red", ""

for i in s1:
   if i == '_':
       s2 += ':' if evenOrOdd else ','
       evenOrOdd = not evenOrOdd
   else:
       s2 += i

print s2

Presently I cannot work out how to use .join instead of += ...
While I realise this is producing a new string (and I believe +=
rebuilds it a lot?) how much slower
is this going to be over the others?



More information about the Python-list mailing list