alternating string replace

Paul Rubin http
Sat Jan 12 03:25:00 CET 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