aboutsummaryrefslogtreecommitdiff
path: root/challenge-308/lubos-kolouch/python/ch-1.py
diff options
context:
space:
mode:
authorLubos Kolouch <lubos@kolouch.net>2025-02-11 15:11:02 +0100
committerLubos Kolouch <lubos@kolouch.net>2025-02-11 15:11:02 +0100
commitb744356b9515b100e6038dc131159feeb255278f (patch)
tree3993685fc154feec90d07b296d9332e5030694d2 /challenge-308/lubos-kolouch/python/ch-1.py
parentd8179c22c12d35d4201bc8e3f759a4a8009e6b1b (diff)
downloadperlweeklychallenge-club-b744356b9515b100e6038dc131159feeb255278f.tar.gz
perlweeklychallenge-club-b744356b9515b100e6038dc131159feeb255278f.tar.bz2
perlweeklychallenge-club-b744356b9515b100e6038dc131159feeb255278f.zip
Challenge 308 LK Perl Python
Diffstat (limited to 'challenge-308/lubos-kolouch/python/ch-1.py')
-rw-r--r--challenge-308/lubos-kolouch/python/ch-1.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/challenge-308/lubos-kolouch/python/ch-1.py b/challenge-308/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..227a3fa942
--- /dev/null
+++ b/challenge-308/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python3
+"""
+Task 1: Count Common
+
+Given two arrays of strings, str1 and str2,
+return the count of common strings in both arrays.
+
+Examples:
+ Input: str1 = ["perl", "weekly", "challenge"]
+ str2 = ["raku", "weekly", "challenge"]
+ Output: 2
+
+ Input: str1 = ["perl", "raku", "python"]
+ str2 = ["python", "java"]
+ Output: 1
+
+ Input: str1 = ["guest", "contribution"]
+ str2 = ["fun", "weekly", "challenge"]
+ Output: 0
+
+"""
+
+import unittest
+
+# typedef: Define a type alias for list of strings.
+StrList = list[str]
+
+
+def count_common(str1: StrList, str2: StrList) -> int:
+ """
+ Count the number of common strings between two lists.
+ """
+ return len(set(str1).intersection(str2))
+
+
+class TestCountCommon(unittest.TestCase):
+
+ def test_example1(self):
+ self.assertEqual(
+ count_common(["perl", "weekly", "challenge"],
+ ["raku", "weekly", "challenge"]), 2)
+
+ def test_example2(self):
+ self.assertEqual(
+ count_common(["perl", "raku", "python"], ["python", "java"]), 1)
+
+ def test_example3(self):
+ self.assertEqual(
+ count_common(["guest", "contribution"],
+ ["fun", "weekly", "challenge"]), 0)
+
+
+if __name__ == '__main__':
+ unittest.main()