diff options
| author | Leo Manfredi <manfredi@cpan.org> | 2020-06-12 18:46:24 +0200 |
|---|---|---|
| committer | Leo Manfredi <manfredi@cpan.org> | 2020-06-12 18:46:24 +0200 |
| commit | 3326f44c45080935ed26e168c9b6e5b0d2dec867 (patch) | |
| tree | d3799f72b5af6bd528f5b5b38a9d6b1288df28bb /challenge-064/manfredi/python/ch-2.py | |
| parent | 4cb5dab951b195c73af94b60a5fb1063158fdde0 (diff) | |
| download | perlweeklychallenge-club-3326f44c45080935ed26e168c9b6e5b0d2dec867.tar.gz perlweeklychallenge-club-3326f44c45080935ed26e168c9b6e5b0d2dec867.tar.bz2 perlweeklychallenge-club-3326f44c45080935ed26e168c9b6e5b0d2dec867.zip | |
Solution for Task #2
Diffstat (limited to 'challenge-064/manfredi/python/ch-2.py')
| -rwxr-xr-x | challenge-064/manfredi/python/ch-2.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-064/manfredi/python/ch-2.py b/challenge-064/manfredi/python/ch-2.py new file mode 100755 index 0000000000..8b83956291 --- /dev/null +++ b/challenge-064/manfredi/python/ch-2.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +# Perl Week Challenge 064 - Task #2 +# You are given a string $S and an array of words @W. +# Write a script to find out if $S can be split into +# sequence of one or more words as in the given @W. +# Print the all the words if found otherwise print 0. + +string = 'perlweeklychallenge' +words = ["weekly", "challenge", "perl"] + +# string = 'perlandraku' +# words = ["python", "ruby", "haskell"] + +slurp = ''.join(words) + +if len(string) != len(slurp): + print(0) + exit() + +pos = {} + +for word in words: + i = string.find(word) + if i == -1: + print(0) + exit() + pos[i] = word + +result = [ pos[x] for x in sorted(pos) ] +print(result) + |
