aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZapwai <zapwai@gmail.com>2024-02-08 12:48:11 -0500
committerGitHub <noreply@github.com>2024-02-08 12:48:11 -0500
commit7e45d7c7dcbc8ca7abfa65a55d124e216729cb80 (patch)
tree05c5b164e1c2d770922a77c2b53766bc9fb55dc7
parent687f556ce8d22ef728f980d4808d41acaf4818f9 (diff)
downloadperlweeklychallenge-club-7e45d7c7dcbc8ca7abfa65a55d124e216729cb80.tar.gz
perlweeklychallenge-club-7e45d7c7dcbc8ca7abfa65a55d124e216729cb80.tar.bz2
perlweeklychallenge-club-7e45d7c7dcbc8ca7abfa65a55d124e216729cb80.zip
Week 255 in Python
-rw-r--r--challenge-255/zapwai/python/ch-1.py25
-rw-r--r--challenge-255/zapwai/python/ch-2.py17
2 files changed, 42 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..1ad73f503f
--- /dev/null
+++ b/challenge-255/zapwai/python/ch-1.py
@@ -0,0 +1,25 @@
+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;
+ for i in range(len(s)):
+ if freqs[s[i]] < freqt[s[i]]:
+ ans = s[i];
+ break;
+ else:
+ for k in freqt.keys():
+ if not k in freqs.keys():
+ ans = k;
+ 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");