aboutsummaryrefslogtreecommitdiff
path: root/challenge-242/roger-bell-west/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-242/roger-bell-west/python/ch-1.py')
-rwxr-xr-xchallenge-242/roger-bell-west/python/ch-1.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-242/roger-bell-west/python/ch-1.py b/challenge-242/roger-bell-west/python/ch-1.py
new file mode 100755
index 0000000000..a4b970b293
--- /dev/null
+++ b/challenge-242/roger-bell-west/python/ch-1.py
@@ -0,0 +1,30 @@
+#! /usr/bin/python3
+
+def unique(a):
+ ss = set()
+ b = []
+ for i in a:
+ if i not in ss:
+ b.append(i)
+ ss.add(i)
+ return b
+
+def halfmissing(a, bh):
+ return unique(i for i in a if i not in bh)
+
+def missingmembers(a, b):
+ ah = set(a)
+ bh = set(b)
+ return [halfmissing(a, bh), halfmissing(b, ah)]
+
+import unittest
+
+class TestMissingmembers(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(missingmembers([1, 2, 3], [2, 4, 6]), [[1, 3], [4, 6]], 'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(missingmembers([1, 2, 3, 3], [1, 1, 2, 2]), [[3], []], 'example 2')
+
+unittest.main()