aboutsummaryrefslogtreecommitdiff
path: root/challenge-256/packy-anderson/python/ch-2.py
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-02-16 20:06:35 +0000
committerGitHub <noreply@github.com>2024-02-16 20:06:35 +0000
commitdf42df8b73d85878b0a58a345f1b9c089dc12e5e (patch)
treed6860613c199d73fd094c9ac2a40df37d0dabc2d /challenge-256/packy-anderson/python/ch-2.py
parentdb57470322df59135d8475ce632b6b016315ac01 (diff)
parentd23fbdd681ca2a9b02c5cb2234caa61d5ec32cef (diff)
downloadperlweeklychallenge-club-df42df8b73d85878b0a58a345f1b9c089dc12e5e.tar.gz
perlweeklychallenge-club-df42df8b73d85878b0a58a345f1b9c089dc12e5e.tar.bz2
perlweeklychallenge-club-df42df8b73d85878b0a58a345f1b9c089dc12e5e.zip
Merge pull request #9591 from packy/master
Challenge 256 solutions by Packy Anderson
Diffstat (limited to 'challenge-256/packy-anderson/python/ch-2.py')
-rwxr-xr-xchallenge-256/packy-anderson/python/ch-2.py23
1 files changed, 23 insertions, 0 deletions
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