An alternative itertools option itertools problem overriding style with repeat() , izip() and chain() :
>>> from itertools import repeat, izip, chain >>> "".join(chain(*izip(*repeat(s, 2)))) '112233aabbcc' >>> "".join(chain(*izip(*repeat(s, 3)))) '111222333aaabbbccc'
Or, "I know regular expressions, and I will use it for everything" - a style option:
>>> import re >>> n = 2 >>> re.sub(".", lambda x: x.group() * n, s)
Of course, do not use these solutions in practice.
source share