MCPcopy
hub / github.com/keon/algorithms / is_anagram

Function is_anagram

algorithms/map/is_anagram.py:17–39  ·  view source on GitHub ↗

Check if string t is an anagram of string s. Args: s: First string. t: Second string. Returns: True if t is an anagram of s, False otherwise. Examples: >>> is_anagram("anagram", "nagaram") True >>> is_anagram("rat", "car") False

(s: str, t: str)

Source from the content-addressed store, hash-verified

15
16
17def is_anagram(s: str, t: str) -> bool:
18 """Check if string t is an anagram of string s.
19
20 Args:
21 s: First string.
22 t: Second string.
23
24 Returns:
25 True if t is an anagram of s, False otherwise.
26
27 Examples:
28 >>> is_anagram("anagram", "nagaram")
29 True
30 >>> is_anagram("rat", "car")
31 False
32 """
33 freq_s: dict[str, int] = {}
34 freq_t: dict[str, int] = {}
35 for char in s:
36 freq_s[char] = freq_s.get(char, 0) + 1
37 for char in t:
38 freq_t[char] = freq_t.get(char, 0) + 1
39 return freq_s == freq_t

Callers 1

test_is_anagramMethod · 0.90

Calls 1

getMethod · 0.45

Tested by 1

test_is_anagramMethod · 0.72