aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-02-08 19:31:09 +0000
committerGitHub <noreply@github.com>2024-02-08 19:31:09 +0000
commit555173034d46783eb8136feb17147d5e593acec8 (patch)
tree625b21c0198923639b2fb53384e5116f01800580
parentd20ebf1497d42214ead503e115277df64c68264e (diff)
parent5d082eda650b759fc16ee940f366af9a2f48832a (diff)
downloadperlweeklychallenge-club-555173034d46783eb8136feb17147d5e593acec8.tar.gz
perlweeklychallenge-club-555173034d46783eb8136feb17147d5e593acec8.tar.bz2
perlweeklychallenge-club-555173034d46783eb8136feb17147d5e593acec8.zip
Merge pull request #9546 from zapwai/branch-for-255
Week 255 in Python
-rw-r--r--challenge-255/zapwai/python/ch-1.py26
-rw-r--r--challenge-255/zapwai/python/ch-2.py17
2 files changed, 43 insertions, 0 deletions
diff --git a/challenge-255/zapwai/python/ch-1.py b/challenge-255/zapwai/python/ch-1.py
new file mode 100644
index 0000000000..96dd77debf
--- /dev/null
+++ b/challenge-255/zapwai/python/ch-1.py
@@ -0,0 +1,26 @@
+def proc(s, t):
+ print("Input: s =",s,"t =",t);
+ freqs = {};
+ freqt = {};
+ for c in s:
+ freqs[c] = 0;
+ for c in s:
+ freqs[c] += 1;
+ for c in t:
+ freqt[c] = 0;
+ for c in t:
+ freqt[c] += 1;
+ ans = None;
+ for k in freqt.keys():
+ if not k in freqs.keys():
+ ans = k;
+ break;
+ if ans is None:
+ for i in range(len(s)):
+ if freqs[s[i]] < freqt[s[i]]:
+ ans = s[i];
+ break;
+ print("Output:",ans);
+proc("Perl", "Preel");
+proc("Weekly", "Weeakly");
+proc("Box", "Boxy");
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");