aboutsummaryrefslogtreecommitdiff
path: root/challenge-256/packy-anderson/python/ch-2.py
diff options
context:
space:
mode:
authorPacky Anderson <packy@cpan.org>2024-02-16 01:14:32 -0500
committerPacky Anderson <packy@cpan.org>2024-02-16 01:14:32 -0500
commitd23fbdd681ca2a9b02c5cb2234caa61d5ec32cef (patch)
tree5a60957ab7b6f8f3907682e982d9ce5560ee29e8 /challenge-256/packy-anderson/python/ch-2.py
parentc9792b8a02f80c49e9bb4f0a1056c98d41e693a4 (diff)
downloadperlweeklychallenge-club-d23fbdd681ca2a9b02c5cb2234caa61d5ec32cef.tar.gz
perlweeklychallenge-club-d23fbdd681ca2a9b02c5cb2234caa61d5ec32cef.tar.bz2
perlweeklychallenge-club-d23fbdd681ca2a9b02c5cb2234caa61d5ec32cef.zip
Challenge 256 solutions by Packy Anderson
* Raku * Perl * Python 1 Blog post
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