diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-01-28 18:15:58 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-28 18:15:58 +0000 |
| commit | ea6144a973f5c2436fe26a424eb195838761c290 (patch) | |
| tree | 0849c0f4e89c91ae59b73aa661a5b8df694a8fd9 | |
| parent | cf444721f65434c09500ded885f7d5626410daa3 (diff) | |
| parent | 77e80aef95a8efd58b8805a190f17c07ca860056 (diff) | |
| download | perlweeklychallenge-club-ea6144a973f5c2436fe26a424eb195838761c290.tar.gz perlweeklychallenge-club-ea6144a973f5c2436fe26a424eb195838761c290.tar.bz2 perlweeklychallenge-club-ea6144a973f5c2436fe26a424eb195838761c290.zip | |
Merge pull request #9474 from oWnOIzRi/week253
add solution week 253 task 1 in python
| -rw-r--r-- | challenge-253/steven-wilson/python/ch-01.py | 18 |
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() |
