aboutsummaryrefslogtreecommitdiff
path: root/challenge-253/roger-bell-west/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-253/roger-bell-west/python')
-rwxr-xr-xchallenge-253/roger-bell-west/python/ch-1.py21
-rwxr-xr-xchallenge-253/roger-bell-west/python/ch-2.py19
2 files changed, 40 insertions, 0 deletions
diff --git a/challenge-253/roger-bell-west/python/ch-1.py b/challenge-253/roger-bell-west/python/ch-1.py
new file mode 100755
index 0000000000..af4f110b05
--- /dev/null
+++ b/challenge-253/roger-bell-west/python/ch-1.py
@@ -0,0 +1,21 @@
+#! /usr/bin/python3
+
+def splitstrings(a, sep):
+ p = []
+ for s in a:
+ for n in s.split(sep):
+ if len(n) > 0:
+ p.append(n)
+ return p
+
+import unittest
+
+class TestSplitstrings(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(splitstrings(["one.two.three", "four.five", "six"], "."), ["one", "two", "three", "four", "five", "six"], 'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(splitstrings(["$perl$$", "$$raku$"], "$"), ["perl", "raku"], 'example 2')
+
+unittest.main()
diff --git a/challenge-253/roger-bell-west/python/ch-2.py b/challenge-253/roger-bell-west/python/ch-2.py
new file mode 100755
index 0000000000..80fa491683
--- /dev/null
+++ b/challenge-253/roger-bell-west/python/ch-2.py
@@ -0,0 +1,19 @@
+#! /usr/bin/python3
+
+def weakestrows(a):
+ p = list(range(len(a)))
+ b = [sum(n) for n in a]
+ p.sort(key = lambda i: b[i])
+ return p
+
+import unittest
+
+class TestWeakestrows(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(weakestrows([[1, 1, 0, 0, 0], [1, 1, 1, 1, 0], [1, 0, 0, 0, 0], [1, 1, 0, 0, 0], [1, 1, 1, 1, 1]]), [2, 0, 3, 1, 4], 'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(weakestrows([[1, 0, 0, 0], [1, 1, 1, 1], [1, 0, 0, 0], [1, 0, 0, 0]]), [0, 2, 3, 1], 'example 2')
+
+unittest.main()