blob: dea6e0dc6d974969b23b31fd15e8e6c001cbd003 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#!/usr/bin/env python3
from itertools import chain
def merge_strings(first, second):
''' Given two strings, merge the given strings by adding in alternative
order starting with the first string. If a string is longer than the other
then append the remaining at the end.
>>> merge_strings("abcd", "1234")
'a1b2c3d4'
>>> merge_strings("abc", "12345")
'a1b2c345'
>>> merge_strings("abcde", "123")
'a1b2c3de'
'''
return ("".join(chain.from_iterable(zip(first, second))) +
first[len(second):] +
second[len(first):])
if __name__ == "__main__":
import doctest
doctest.testmod()
|