From 634828dcc271a6a79dc863a0827e71e818f8b7ca Mon Sep 17 00:00:00 2001 From: Harishankar Mohapatra Date: Thu, 12 Feb 2026 11:26:21 +0530 Subject: [PATCH 1/2] Add string_statistics algorithms. --- strings/string_statistics.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 strings/string_statistics.py diff --git a/strings/string_statistics.py b/strings/string_statistics.py new file mode 100644 index 000000000000..c4ff10aab36d --- /dev/null +++ b/strings/string_statistics.py @@ -0,0 +1,26 @@ +def string_statistics(text: str) -> dict[str, int]: + """ + Return statistics about a string. + + >>> string_statistics("Hello") + {'length': 5, 'vowels': 2, 'consonants': 3} + + >>> string_statistics("") + {'length': 0, 'vowels': 0, 'consonants': 0} + """ + vowels = "aeiouAEIOU" + + length = len(text) + vowel_count = sum(1 for char in text if char in vowels) + consonant_count = sum(1 for char in text if char.isalpha() and char not in vowels) + + return { + "length": length, + "vowels": vowel_count, + "consonants": consonant_count, + } + + +if __name__ == "__main__": + from doctest import testmod + testmod() \ No newline at end of file From 511e81a420bde7663ad70cfa5e582a1792eafbb6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 12 Feb 2026 06:12:09 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/string_statistics.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/strings/string_statistics.py b/strings/string_statistics.py index c4ff10aab36d..8a8ed4b87b16 100644 --- a/strings/string_statistics.py +++ b/strings/string_statistics.py @@ -23,4 +23,5 @@ def string_statistics(text: str) -> dict[str, int]: if __name__ == "__main__": from doctest import testmod - testmod() \ No newline at end of file + + testmod()