diff options
| author | Simon Green <mail@simon.green> | 2024-11-17 20:40:19 +1100 |
|---|---|---|
| committer | Simon Green <mail@simon.green> | 2024-11-17 20:40:19 +1100 |
| commit | fe00ecfb7362652b3d450000cd099f4044775cfd (patch) | |
| tree | ce353e375954d457e1fa26069104aaf436b57a5a /challenge-295/sgreen/python/ch-1.py | |
| parent | 7ce82fc7f6821082ec19358e597a3e4843c7ab51 (diff) | |
| download | perlweeklychallenge-club-fe00ecfb7362652b3d450000cd099f4044775cfd.tar.gz perlweeklychallenge-club-fe00ecfb7362652b3d450000cd099f4044775cfd.tar.bz2 perlweeklychallenge-club-fe00ecfb7362652b3d450000cd099f4044775cfd.zip | |
sgreen solutions to challenge 295
Diffstat (limited to 'challenge-295/sgreen/python/ch-1.py')
| -rwxr-xr-x | challenge-295/sgreen/python/ch-1.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/challenge-295/sgreen/python/ch-1.py b/challenge-295/sgreen/python/ch-1.py new file mode 100755 index 0000000000..bed823f512 --- /dev/null +++ b/challenge-295/sgreen/python/ch-1.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 + +import re +import sys + + +def word_break(s: str, words: list) -> bool: + # Turn the words into a regular expression + pattern = '^(' + '|'.join(map(re.escape, words)) + ')+$' + + # Check if the string matches the pattern + return True if re.search(pattern, s) else False + + +def main(): + # The first value is the string, the rest are the words + result = word_break(sys.argv[1], sys.argv[2:]) + print('true' if result else 'false') + + +if __name__ == '__main__': + main() |
