aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven <steven1170@zoho.eu>2024-01-28 17:03:32 +0000
committerSteven <steven1170@zoho.eu>2024-01-28 17:03:32 +0000
commit77e80aef95a8efd58b8805a190f17c07ca860056 (patch)
tree3514cd76747f292e6d5bcc950fe88ba066253b99
parentcda5876d6dad1b64c91468748dc3be4d708d0789 (diff)
downloadperlweeklychallenge-club-77e80aef95a8efd58b8805a190f17c07ca860056.tar.gz
perlweeklychallenge-club-77e80aef95a8efd58b8805a190f17c07ca860056.tar.bz2
perlweeklychallenge-club-77e80aef95a8efd58b8805a190f17c07ca860056.zip
add solution week 253 task 1 in python
-rw-r--r--challenge-253/steven-wilson/python/ch-01.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/challenge-253/steven-wilson/python/ch-01.py b/challenge-253/steven-wilson/python/ch-01.py
new file mode 100644
index 0000000000..d6f4bf74ca
--- /dev/null
+++ b/challenge-253/steven-wilson/python/ch-01.py
@@ -0,0 +1,18 @@
+#!/usr/bin/env python3
+
+
+def split_strings(*strings, separator=","):
+ ''' Given an array of strings and a character separator.
+ Return all words separated by the given character excluding empty strings
+ >>> split_strings("one.two.three","four.five","six", separator=".")
+ ['one', 'two', 'three', 'four', 'five', 'six']
+ >>> split_strings("$perl$$", "$$raku$", separator="$")
+ ['perl', 'raku']
+ '''
+ return [word for string in strings for word in string.split(separator) if word != ""]
+
+
+if __name__ == "__main__":
+ import doctest
+
+ doctest.testmod()