From d23fbdd681ca2a9b02c5cb2234caa61d5ec32cef Mon Sep 17 00:00:00 2001 From: Packy Anderson Date: Fri, 16 Feb 2024 01:14:32 -0500 Subject: Challenge 256 solutions by Packy Anderson * Raku * Perl * Python 1 Blog post --- challenge-256/packy-anderson/python/ch-2.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 challenge-256/packy-anderson/python/ch-2.py (limited to 'challenge-256/packy-anderson/python/ch-2.py') diff --git a/challenge-256/packy-anderson/python/ch-2.py b/challenge-256/packy-anderson/python/ch-2.py new file mode 100755 index 0000000000..a178ffab9e --- /dev/null +++ b/challenge-256/packy-anderson/python/ch-2.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +def mergeStrings(str1, str2): + chars1 = list(str1) + chars2 = list(str2) + result = '' + while chars1 or chars2: + if chars1: + result += chars1.pop(0) + if chars2: + result += chars2.pop(0) + return result + +def solution(str1, str2): + print(f'Input: $str1 = "{str1}", $str2 = "{str2}"') + output = mergeStrings(str1, str2) + print(f'Output: {output}') + +print('Example 1:') +solution("abcd", "1234") + +print('\nExample 2:') +solution("abc", "12345") \ No newline at end of file -- cgit