diff options
| author | Roger Bell_West <roger@firedrake.org> | 2025-05-13 14:06:50 +0100 |
|---|---|---|
| committer | Roger Bell_West <roger@firedrake.org> | 2025-05-13 14:06:50 +0100 |
| commit | aa6afc31ada526c649d8490e9bdcb416027686f2 (patch) | |
| tree | 8a6a19b64ac7a3463e4e0b99d62cc2d7053b7b57 /challenge-321/roger-bell-west/python/ch-2.py | |
| parent | 152c0ffaaa3df8dfa2a5dbff97971ec378999b0a (diff) | |
| download | perlweeklychallenge-club-aa6afc31ada526c649d8490e9bdcb416027686f2.tar.gz perlweeklychallenge-club-aa6afc31ada526c649d8490e9bdcb416027686f2.tar.bz2 perlweeklychallenge-club-aa6afc31ada526c649d8490e9bdcb416027686f2.zip | |
RogerBW solutions for challenge no. 321
Diffstat (limited to 'challenge-321/roger-bell-west/python/ch-2.py')
| -rwxr-xr-x | challenge-321/roger-bell-west/python/ch-2.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-321/roger-bell-west/python/ch-2.py b/challenge-321/roger-bell-west/python/ch-2.py new file mode 100755 index 0000000000..baf1c7a1c7 --- /dev/null +++ b/challenge-321/roger-bell-west/python/ch-2.py @@ -0,0 +1,28 @@ +#! /usr/bin/python3 + +def backspacecompare(a, b): + sa = [] + for i in [a, b]: + oa = [] + for c in i: + if c == "#": + oa.pop() + else: + oa.append(c) + sa.append("".join(oa)) + return sa[0] == sa[1] + +import unittest + +class TestBackspacecompare(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(backspacecompare("ab#c", "ad#c"), True, 'example 1') + + def test_ex2(self): + self.assertEqual(backspacecompare("ab##", "a#b#"), True, 'example 2') + + def test_ex3(self): + self.assertEqual(backspacecompare("a#b", "c"), False, 'example 3') + +unittest.main() |
