diff options
Diffstat (limited to 'challenge-255/zapwai/python/ch-2.py')
| -rw-r--r-- | challenge-255/zapwai/python/ch-2.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/challenge-255/zapwai/python/ch-2.py b/challenge-255/zapwai/python/ch-2.py new file mode 100644 index 0000000000..5a7a0a620b --- /dev/null +++ b/challenge-255/zapwai/python/ch-2.py @@ -0,0 +1,17 @@ +def proc(p, w): + words = p.split(); + freq = {}; + for word in words: + if not word[len(word)-1].isalpha(): + word = word[:-1]; + if not word == w: + freq[word] = 0; + for word in words: + if not word[len(word)-1].isalpha(): + word = word[:-1]; + if not word == w: + freq[word] += 1; + print("Input: p =", p, "\n\tw =", w); + print("Output:",max(freq, key=freq.get)); +proc("Joe hit a ball, the hit ball flew far after it was hit.", "hit"); +proc("Perl and Raku belong to the same family. Perl is the most popular language in the weekly challenge.","the"); |
