alternating string replace

Paul Rubin http
Fri Jan 11 21:25:00 EST 2008


George Sakkis <george.sakkis at gmail.com> writes:
> from itertools import chain, izip, cycle
> print ''.join(chain(*izip(s1.split('_'),cycle(':,'))))[:-1]

from itertools import cycle
a = cycle(':,')
print re.sub('_', lambda x: a.next(), s1)



More information about the Python-list mailing list