diff options
| author | Simon Green <mail@simon.green> | 2024-02-18 22:06:17 +1100 |
|---|---|---|
| committer | Simon Green <mail@simon.green> | 2024-02-18 22:06:17 +1100 |
| commit | f26d5bb6358c8586add2fc520ed98651688fc2cb (patch) | |
| tree | 6423761ddb359fb89ad0dcf2d7d4c625e0a96620 /challenge-256/sgreen/python/ch-2.py | |
| parent | 3f3e0798a68401ce1d67a5e1534f69de16856e82 (diff) | |
| download | perlweeklychallenge-club-f26d5bb6358c8586add2fc520ed98651688fc2cb.tar.gz perlweeklychallenge-club-f26d5bb6358c8586add2fc520ed98651688fc2cb.tar.bz2 perlweeklychallenge-club-f26d5bb6358c8586add2fc520ed98651688fc2cb.zip | |
Simon's solution to challenge 256
Diffstat (limited to 'challenge-256/sgreen/python/ch-2.py')
| -rwxr-xr-x | challenge-256/sgreen/python/ch-2.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-256/sgreen/python/ch-2.py b/challenge-256/sgreen/python/ch-2.py new file mode 100755 index 0000000000..051efa1d4c --- /dev/null +++ b/challenge-256/sgreen/python/ch-2.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +import sys +from itertools import zip_longest + + +def merge_strings(words: list) -> str: + """Merge strings together by taking the first character from each word, + then the second, and so on. + + Args: + words (list): A list of words + + Returns: + str: The merged string + """ + return ''.join(''.join(s) for s in zip_longest(*words, fillvalue='')) + + +def main(): + result = merge_strings(sys.argv[1:]) + print(result) + + +if __name__ == '__main__': + main() |
