aboutsummaryrefslogtreecommitdiff
path: root/challenge-215/lance-wicks/python
diff options
context:
space:
mode:
authorlancew <lw@judocoach.com>2023-05-06 14:15:07 +0100
committerlancew <lw@judocoach.com>2023-05-06 14:15:07 +0100
commit987b0225e4b17bd14e7f73c484573e42c92a7463 (patch)
tree51c68ce09ae16bf4edfd0a7e4c658b3a5df7275c /challenge-215/lance-wicks/python
parentfca710e33f9f55af0a163c95ad060a4d1c6e7be5 (diff)
downloadperlweeklychallenge-club-987b0225e4b17bd14e7f73c484573e42c92a7463.tar.gz
perlweeklychallenge-club-987b0225e4b17bd14e7f73c484573e42c92a7463.tar.bz2
perlweeklychallenge-club-987b0225e4b17bd14e7f73c484573e42c92a7463.zip
Python attempt at challenge 215
Diffstat (limited to 'challenge-215/lance-wicks/python')
-rw-r--r--challenge-215/lance-wicks/python/OddOneOut-tests.py24
-rw-r--r--challenge-215/lance-wicks/python/ch-1.py5
-rw-r--r--challenge-215/lance-wicks/python/oddoneout.py13
3 files changed, 42 insertions, 0 deletions
diff --git a/challenge-215/lance-wicks/python/OddOneOut-tests.py b/challenge-215/lance-wicks/python/OddOneOut-tests.py
new file mode 100644
index 0000000000..26d476520f
--- /dev/null
+++ b/challenge-215/lance-wicks/python/OddOneOut-tests.py
@@ -0,0 +1,24 @@
+import unittest
+
+from oddoneout import *
+
+class TestNotAlphaOrder(unittest.TestCase):
+
+ def test_order_one(self):
+ self.assertFalse(is_not_alpha_order('abc'))
+ def test_order_two(self):
+ self.assertTrue(is_not_alpha_order('cba'))
+
+class TestCount(unittest.TestCase):
+ def test_count_example_one(self):
+ words = ['abc', 'xyz', 'tsu']
+ self.assertEqual(count(words),1)
+ def test_count_example_two(self):
+ words = ['rat', 'cab', 'dad']
+ self.assertEqual(count(words),3)
+ def test_count_example_three(self):
+ words = ['x', 'y', 'z']
+ self.assertEqual(count(words),0)
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/challenge-215/lance-wicks/python/ch-1.py b/challenge-215/lance-wicks/python/ch-1.py
new file mode 100644
index 0000000000..7c56a293b5
--- /dev/null
+++ b/challenge-215/lance-wicks/python/ch-1.py
@@ -0,0 +1,5 @@
+import sys
+import oddoneout
+
+print('Input: ', sys.argv[1:])
+print('Output: ', oddoneout.count(sys.argv[1:]))
diff --git a/challenge-215/lance-wicks/python/oddoneout.py b/challenge-215/lance-wicks/python/oddoneout.py
new file mode 100644
index 0000000000..5ec80b00f4
--- /dev/null
+++ b/challenge-215/lance-wicks/python/oddoneout.py
@@ -0,0 +1,13 @@
+def is_not_alpha_order(word):
+ letters = [*word]
+ letters.sort()
+ sorted_word = ''.join(letters)
+ return word != sorted_word
+
+def count(words):
+ total = 0
+
+ for word in words:
+ if is_not_alpha_order(word):
+ total += 1
+ return total