File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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" ))
Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments