Skip to content

Commit 1619b30

Browse files
committed
feat(day 44): implement string mirror checker ignoring non-alphabet characters
1 parent 289320c commit 1619b30

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
String Mirror
3+
Given two strings, determine if the second string is a mirror of the first.
4+
5+
A string is considered a mirror if it contains the same letters in reverse order.
6+
Treat uppercase and lowercase letters as distinct.
7+
Ignore all non-alphabetical characters.
8+
9+
"""
10+
11+
def is_mirror(str1,str2):
12+
13+
refined_str1 = ''.join(char for char in str1 if char.isalpha())
14+
refined_str2 = ''.join(char for char in str2 if char.isalpha())
15+
16+
17+
return refined_str1 == refined_str2[::-1]
18+
19+
20+
if __name__ == "__main__":
21+
22+
print(is_mirror("helloworld","helloworld"))
23+
print(is_mirror("Hello World","dlroW olleH"))
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import unittest
2+
3+
from StringMirror import is_mirror
4+
5+
class StringMirrorTest(unittest.TestCase):
6+
7+
def test1(self):
8+
self.assertEqual(is_mirror("helloworld","helloworld"),False)
9+
10+
def test2(self):
11+
self.assertEqual(is_mirror("Hello World", "dlroW olleH"),True)
12+
13+
def test3(self):
14+
self.assertEqual(is_mirror("RaceCar", "raCecaR"),True)
15+
16+
def test4(self):
17+
self.assertEqual(is_mirror("RaceCar", "RaceCar"),False)
18+
19+
def test5(self):
20+
self.assertEqual(is_mirror("Mirror", "rorrim"),False)
21+
22+
def test6(self):
23+
self.assertEqual(is_mirror("Hello World", "dlroW-olleH"),True)
24+
25+
def test7(self):
26+
self.assertEqual(is_mirror("Hello World", "!dlroW !olleH"),True)
27+
28+
29+
30+
if __name__ == "__main__":
31+
unittest.main()

0 commit comments

Comments
 (0)