diff options
| author | Steven <steven1170@zoho.eu> | 2024-02-12 17:26:31 +0000 |
|---|---|---|
| committer | Steven <steven1170@zoho.eu> | 2024-02-12 17:26:31 +0000 |
| commit | 2b637ebaee0ee2c82474f2364e5a4cfa0fb7d828 (patch) | |
| tree | a12d4af83aa4aafb2ef22d31eb95b7ac9f3c6768 /challenge-256/steven-wilson/python/ch-2.py | |
| parent | 3f3e0798a68401ce1d67a5e1534f69de16856e82 (diff) | |
| download | perlweeklychallenge-club-2b637ebaee0ee2c82474f2364e5a4cfa0fb7d828.tar.gz perlweeklychallenge-club-2b637ebaee0ee2c82474f2364e5a4cfa0fb7d828.tar.bz2 perlweeklychallenge-club-2b637ebaee0ee2c82474f2364e5a4cfa0fb7d828.zip | |
add solutions week 256 in python
Diffstat (limited to 'challenge-256/steven-wilson/python/ch-2.py')
| -rw-r--r-- | challenge-256/steven-wilson/python/ch-2.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-256/steven-wilson/python/ch-2.py b/challenge-256/steven-wilson/python/ch-2.py new file mode 100644 index 0000000000..dea6e0dc6d --- /dev/null +++ b/challenge-256/steven-wilson/python/ch-2.py @@ -0,0 +1,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() |
