From f26d5bb6358c8586add2fc520ed98651688fc2cb Mon Sep 17 00:00:00 2001 From: Simon Green Date: Sun, 18 Feb 2024 22:06:17 +1100 Subject: Simon's solution to challenge 256 --- challenge-256/sgreen/python/ch-2.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 challenge-256/sgreen/python/ch-2.py (limited to 'challenge-256/sgreen/python/ch-2.py') 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() -- cgit