Here is one way to do it.
>>> s1 = "abc" >>> s2 = "xyz" >>> "".join(i for j in zip(s1, s2) for i in j) 'axbycz'
It also works for more than 2 lines
>>> s3 = "123" >>> "".join(i for j in zip(s1, s2, s3) for i in j) 'ax1by2cz3'
Here is another way
>>> "".join("".join(i) for i in zip(s1,s2,s3)) 'ax1by2cz3'
And further
>>> from itertools import chain >>> "".join(chain(*zip(s1, s2, s3))) 'ax1by2cz3'
And one without zip
>>> b = bytearray(6) >>> b[::2] = "abc" >>> b[1::2] = "xyz" >>> str(b) 'axbycz'
And ineffective
>>> ((s1 + " " + s2) * len(s1))[::len(s1) + 1] 'axbycz'
John la rooy
source share