aboutsummaryrefslogtreecommitdiff
path: root/challenge-278/roger-bell-west/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-278/roger-bell-west/python')
-rwxr-xr-xchallenge-278/roger-bell-west/python/ch-1.py28
-rwxr-xr-xchallenge-278/roger-bell-west/python/ch-2.py25
2 files changed, 53 insertions, 0 deletions
diff --git a/challenge-278/roger-bell-west/python/ch-1.py b/challenge-278/roger-bell-west/python/ch-1.py
new file mode 100755
index 0000000000..fbed9dc486
--- /dev/null
+++ b/challenge-278/roger-bell-west/python/ch-1.py
@@ -0,0 +1,28 @@
+#! /usr/bin/python3
+
+import re
+
+def sortstring(a):
+ words = a.split(" ")
+ out = words.copy()
+ pr = re.compile(r'^(.*?)([0-9]+)$')
+ for w in words:
+ c = pr.search(w)
+ index = int(c.group(2)) - 1
+ out[index] = c.group(1)
+ return " ".join(out)
+
+import unittest
+
+class TestSortstring(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(sortstring("and2 Raku3 cousins5 Perl1 are4"), "Perl and Raku are cousins", 'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(sortstring("guest6 Python1 most4 the3 popular5 is2 language7"), "Python is the most popular guest language", 'example 2')
+
+ def test_ex3(self):
+ self.assertEqual(sortstring("Challenge3 The1 Weekly2"), "The Weekly Challenge", 'example 3')
+
+unittest.main()
diff --git a/challenge-278/roger-bell-west/python/ch-2.py b/challenge-278/roger-bell-west/python/ch-2.py
new file mode 100755
index 0000000000..aa6af5663a
--- /dev/null
+++ b/challenge-278/roger-bell-west/python/ch-2.py
@@ -0,0 +1,25 @@
+#! /usr/bin/python3
+
+def reverseword(a, c):
+ s = a.find(c)
+ if s == -1:
+ return a
+ b = list(a[0:s+1])
+ b.sort()
+ b.extend(list(a[s+1:]))
+ return "".join(b)
+
+import unittest
+
+class TestReverseword(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(reverseword("challenge", "e"), "acehllnge", 'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(reverseword("programming", "a"), "agoprrmming", 'example 2')
+
+ def test_ex3(self):
+ self.assertEqual(reverseword("champion", "b"), "champion", 'example 3')
+
+unittest.main()