diff options
Diffstat (limited to 'challenge-255/roger-bell-west/python/ch-1.py')
| -rwxr-xr-x | challenge-255/roger-bell-west/python/ch-1.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-255/roger-bell-west/python/ch-1.py b/challenge-255/roger-bell-west/python/ch-1.py new file mode 100755 index 0000000000..4e36a5c865 --- /dev/null +++ b/challenge-255/roger-bell-west/python/ch-1.py @@ -0,0 +1,29 @@ +#! /usr/bin/python3 + +from collections import defaultdict + +def oddcharacter(s, t): + ss = defaultdict(lambda: 0) + for c in s: + ss[c] += 1 + for c in t: + if c in ss and ss[c] > 0: + ss[c] -= 1 + else: + return c + return "@" + +import unittest + +class TestOddcharacter(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(oddcharacter("Perl", "Preel"), "e", 'example 1') + + def test_ex2(self): + self.assertEqual(oddcharacter("Weekly", "Weeakly"), "a", 'example 2') + + def test_ex3(self): + self.assertEqual(oddcharacter("Box", "Boxy"), "y", 'example 3') + +unittest.main() |
