File tree Expand file tree Collapse file tree 2 files changed +6
-5
lines changed Expand file tree Collapse file tree 2 files changed +6
-5
lines changed Original file line number Diff line number Diff line change 6
6
7
7
8
8
# Method 1: Using Sorting
9
- def are_anagrams_sorting (str1 , str2 ) :
9
+ def are_anagrams_sorting (str1 : str , str2 : str ) -> bool :
10
10
"""
11
11
Determines if two strings are anagrams by sorting.
12
12
"""
@@ -19,7 +19,7 @@ def are_anagrams_sorting(str1, str2):
19
19
20
20
21
21
# Method 2: Using Character Count with defaultdict for both strings
22
- def are_anagrams_dict (str1 , str2 ) :
22
+ def are_anagrams_dict (str1 : str , str2 : str ) -> bool :
23
23
"""Determines if two strings are anagrams by counting characters with defaultdict for both strings."""
24
24
# Remove whitespace and convert to lowercase for case-insensitive comparison
25
25
str1 = str1 .replace (" " , "" ).lower ()
@@ -43,7 +43,7 @@ def are_anagrams_dict(str1, str2):
43
43
44
44
45
45
# Method 3: Using Character Count with Array (assuming ASCII characters)
46
- def are_anagrams_array (str1 , str2 ) :
46
+ def are_anagrams_array (str1 : str , str2 : str ) -> bool :
47
47
"""Determines if two strings are anagrams by counting characters with an array.
48
48
49
49
Assumes only ASCII characters.
Original file line number Diff line number Diff line change 1
1
"""Test cases for the anagram module."""
2
+ # mypy: ignore-errors
2
3
3
4
import unittest
4
5
@@ -30,7 +31,7 @@ def test_are_anagrams_sorting(self):
30
31
f"Failed for { str1 } and { str2 } " ,
31
32
)
32
33
33
- def test_are_anagrams_dict (self ):
34
+ def test_are_anagrams_dict (self ) -> None :
34
35
"""Test the are_anagrams_dict function."""
35
36
for str1 , str2 , expected in self .test_cases :
36
37
with self .subTest (str1 = str1 , str2 = str2 ):
@@ -40,7 +41,7 @@ def test_are_anagrams_dict(self):
40
41
f"Failed for { str1 } and { str2 } " ,
41
42
)
42
43
43
- def test_are_anagrams_array (self ):
44
+ def test_are_anagrams_array (self ) -> None :
44
45
"""Test the are_anagrams_array function."""
45
46
for str1 , str2 , expected in self .test_cases :
46
47
with self .subTest (str1 = str1 , str2 = str2 ):
You can’t perform that action at this time.
0 commit comments