aboutsummaryrefslogtreecommitdiff
path: root/challenge-340
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <mohammad.anwar@yahoo.com>2025-09-23 00:33:36 +0100
committerMohammad Sajid Anwar <mohammad.anwar@yahoo.com>2025-09-23 00:33:36 +0100
commitc410a0181e730b574b7c8f80700d62d3cfb6fdc8 (patch)
treed009944e9ed051a923269bc7bc8e68f1157faa43 /challenge-340
parentc814a4f210ee95fc6d6c6386bfd42f4c254f14ee (diff)
downloadperlweeklychallenge-club-c410a0181e730b574b7c8f80700d62d3cfb6fdc8.tar.gz
perlweeklychallenge-club-c410a0181e730b574b7c8f80700d62d3cfb6fdc8.tar.bz2
perlweeklychallenge-club-c410a0181e730b574b7c8f80700d62d3cfb6fdc8.zip
- Added Python solution to task 1 of week 340.
Diffstat (limited to 'challenge-340')
-rw-r--r--challenge-340/mohammad-anwar/python/ch-1.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-340/mohammad-anwar/python/ch-1.py b/challenge-340/mohammad-anwar/python/ch-1.py
new file mode 100644
index 0000000000..5f7bad6762
--- /dev/null
+++ b/challenge-340/mohammad-anwar/python/ch-1.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+
+import unittest
+
+def remove_duplicates(s: str) -> str:
+ if len(s) < 2:
+ return s
+
+ for i in range(len(s) - 1):
+ if s[i] == s[i + 1]:
+ new_str = s[:i] + s[i + 2:]
+ return remove_duplicates(new_str)
+
+ return s
+
+class TestRemoveDuplicates(unittest.TestCase):
+ def test_examples(self):
+ examples = {
+ 1: {'str': 'abbaca', 'exp': 'ca'},
+ 2: {'str': 'azxxzy', 'exp': 'ay'},
+ 3: {'str': 'aaaaaaaa', 'exp': ''},
+ 4: {'str': 'aabccba', 'exp': 'a'},
+ 5: {'str': 'abcddcba', 'exp': ''},
+ }
+
+ for example_id, example_data in examples.items():
+ with self.subTest(example_id=example_id, example_str=example_data['str']):
+ result = remove_duplicates(example_data['str'])
+ self.assertEqual(result, example_data['exp'])
+
+if __name__ == '__main__':
+ unittest.main()