diff options
| author | sangeet <sangeet.kar@gmail.com> | 2020-06-10 08:01:53 +0000 |
|---|---|---|
| committer | sangeet <sangeet.kar@gmail.com> | 2020-06-10 08:01:53 +0000 |
| commit | da076644bf4c8750a1b168ba19045d9398c6c4f2 (patch) | |
| tree | e2802c4bde8382f64fd86f5278e45a9baa50d4b8 | |
| parent | e13ce2417a717e4c49ea8010502c4c3776505ad6 (diff) | |
| download | perlweeklychallenge-club-da076644bf4c8750a1b168ba19045d9398c6c4f2.tar.gz perlweeklychallenge-club-da076644bf4c8750a1b168ba19045d9398c6c4f2.tar.bz2 perlweeklychallenge-club-da076644bf4c8750a1b168ba19045d9398c6c4f2.zip | |
Python done
| -rwxr-xr-x | challenge-064/sangeet-kar/python/ch-2.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/challenge-064/sangeet-kar/python/ch-2.py b/challenge-064/sangeet-kar/python/ch-2.py new file mode 100755 index 0000000000..a11a70ab8b --- /dev/null +++ b/challenge-064/sangeet-kar/python/ch-2.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +def word_break(string, words): + ans = [] + recursive_helper(string, words, [], ans) + return ans + +def recursive_helper(string, words, accum, ans): + if not string: + ans.append(accum) + return + for word in words: + if string.startswith(word): + recursive_helper(string[len(word):], words, accum + [word], ans) + + +print(word_break("perlweeklychallenge", ["weekly", "challenge", "perl"])) +print(word_break("perlandraku", ["python", "ruby", "haskell"])) + +# multiple solutions +print(word_break("perlandraku", ["perl", "perland", "raku", "and"])) |
