We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 678dedb commit 634828dCopy full SHA for 634828d
strings/string_statistics.py
@@ -0,0 +1,26 @@
1
+def string_statistics(text: str) -> dict[str, int]:
2
+ """
3
+ Return statistics about a string.
4
+
5
+ >>> string_statistics("Hello")
6
+ {'length': 5, 'vowels': 2, 'consonants': 3}
7
8
+ >>> string_statistics("")
9
+ {'length': 0, 'vowels': 0, 'consonants': 0}
10
11
+ vowels = "aeiouAEIOU"
12
13
+ length = len(text)
14
+ vowel_count = sum(1 for char in text if char in vowels)
15
+ consonant_count = sum(1 for char in text if char.isalpha() and char not in vowels)
16
17
+ return {
18
+ "length": length,
19
+ "vowels": vowel_count,
20
+ "consonants": consonant_count,
21
+ }
22
23
24
+if __name__ == "__main__":
25
+ from doctest import testmod
26
+ testmod()
0 commit comments