I had a question for a test where I had to interlace letters from two strings into one, I did it using the following code:
'abcd' and 'efghi' -> 'aebfcgdhi'
s1,s2='abcd' ,'efghi'
t=[a+b for a,b in zip(s1, s2) ]
ls1 = len(s1)
ls2 = len(s2)
if ls1 > ls2:
t.extend(s1[ls2:])
elif ls1 < ls2:
t.extend(s2[ls1:])
print ''.join(t)
I first tried using the following which seems to work only when strings are the same length or s2 is the longer string.
print ''.join([a+b for a,b in zip(s1, s2)]) + max(s1,s2)[min(len(s1),len(s2)):]
Where did I go wrong in my logic?