Coverage for pytestzoo/strings.py: 100.00%
14 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-08-12 01:37 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-08-12 01:37 +0000
1import unicodedata
3def reverse_string(s: str) -> str:
4 """Reverses the given string."""
5 return s[::-1]
8def is_palindrome(s: str) -> bool:
9 """Returns True if the string is a palindrome."""
10 s_clean = ''.join(c.lower() for c in s if c.isalnum())
11 return s_clean == reverse_string(s_clean)
14def strip_accents(s: str) -> str:
15 """Remove accents from a string."""
16 return ''.join(
17 c for c in unicodedata.normalize('NFKD', s)
18 if not unicodedata.combining(c)
19 )
22def count_vowels(s: str) -> int:
23 """Counts the number of vowels in the string."""
24 # Normalize the string to NFKC form
25 s_normalized = strip_accents(s)
27 # Lowercase and filter to alphabetic characters
28 clean_string = ''.join(c.lower() for c in s_normalized if c.isalpha())
30 return sum(1 for c in clean_string if c in 'aeiou')
33def lowercase(s: str) -> str:
34 """Convert the string to lowercase."""
35 return s.lower()