diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-05-15 02:04:41 +0100 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-05-15 02:04:41 +0100 |
| commit | 7c2f0c2b6a4c20869050372368f5767a80eeeff1 (patch) | |
| tree | 2daeb86605a8937fa3649ffae66e66b44f75c216 /challenge-321/roger-bell-west/python/ch-2.py | |
| parent | a799bc96049a853dae3a0b8bf14c4eb581a4a4ba (diff) | |
| parent | 6e7171bbc384a1e7dbb271587b80b593ccaec1d3 (diff) | |
| download | perlweeklychallenge-club-7c2f0c2b6a4c20869050372368f5767a80eeeff1.tar.gz perlweeklychallenge-club-7c2f0c2b6a4c20869050372368f5767a80eeeff1.tar.bz2 perlweeklychallenge-club-7c2f0c2b6a4c20869050372368f5767a80eeeff1.zip | |
Merge remote-tracking branch 'refs/remotes/origin/master'
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() |
