From 0facd8bb7a145e4664dcc4f6e5b542e36c94eadc Mon Sep 17 00:00:00 2001 From: Tithi Joshi Date: Sat, 7 Feb 2026 08:37:12 +0530 Subject: [PATCH 1/3] refactor: simplify character filtering in is_pangram Refactored is_pangram function to use isalpha for letter check and removed benchmark function. --- strings/is_pangram.py | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/strings/is_pangram.py b/strings/is_pangram.py index c8b894b7ea31..5d8cd5b68497 100644 --- a/strings/is_pangram.py +++ b/strings/is_pangram.py @@ -21,13 +21,10 @@ def is_pangram( >>> is_pangram() True """ - # Declare frequency as a set to have unique occurrences of letters frequency = set() - - # Replace all the whitespace in our sentence input_str = input_str.replace(" ", "") for alpha in input_str: - if "a" <= alpha.lower() <= "z": + if alpha.isalpha(): frequency.add(alpha.lower()) return len(frequency) == 26 @@ -73,23 +70,6 @@ def is_pangram_fastest( """ return len({char for char in input_str.lower() if char.isalpha()}) == 26 - -def benchmark() -> None: - """ - Benchmark code comparing different version. - """ - from timeit import timeit - - setup = "from __main__ import is_pangram, is_pangram_faster, is_pangram_fastest" - print(timeit("is_pangram()", setup=setup)) - print(timeit("is_pangram_faster()", setup=setup)) - print(timeit("is_pangram_fastest()", setup=setup)) - # 5.348480500048026, 2.6477354579837993, 1.8470395830227062 - # 5.036091582966037, 2.644472333951853, 1.8869528750656173 - - -if __name__ == "__main__": - import doctest - - doctest.testmod() - benchmark() + + + From 92ba0df2b929f6956a6c0db2c49b2836061b1e30 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 7 Feb 2026 03:08:32 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/is_pangram.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/strings/is_pangram.py b/strings/is_pangram.py index 5d8cd5b68497..64d3420d1ed2 100644 --- a/strings/is_pangram.py +++ b/strings/is_pangram.py @@ -69,7 +69,3 @@ def is_pangram_fastest( True """ return len({char for char in input_str.lower() if char.isalpha()}) == 26 - - - - From bacc64fc61628188f204012c61807534c738b1fd Mon Sep 17 00:00:00 2001 From: Tithi Joshi Date: Sat, 7 Feb 2026 08:49:48 +0530 Subject: [PATCH 3/3] Implement benchmark for pangram functions Added a benchmark function to compare performance of different is_pangram implementations. --- strings/is_pangram.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/strings/is_pangram.py b/strings/is_pangram.py index 64d3420d1ed2..c8b894b7ea31 100644 --- a/strings/is_pangram.py +++ b/strings/is_pangram.py @@ -21,10 +21,13 @@ def is_pangram( >>> is_pangram() True """ + # Declare frequency as a set to have unique occurrences of letters frequency = set() + + # Replace all the whitespace in our sentence input_str = input_str.replace(" ", "") for alpha in input_str: - if alpha.isalpha(): + if "a" <= alpha.lower() <= "z": frequency.add(alpha.lower()) return len(frequency) == 26 @@ -69,3 +72,24 @@ def is_pangram_fastest( True """ return len({char for char in input_str.lower() if char.isalpha()}) == 26 + + +def benchmark() -> None: + """ + Benchmark code comparing different version. + """ + from timeit import timeit + + setup = "from __main__ import is_pangram, is_pangram_faster, is_pangram_fastest" + print(timeit("is_pangram()", setup=setup)) + print(timeit("is_pangram_faster()", setup=setup)) + print(timeit("is_pangram_fastest()", setup=setup)) + # 5.348480500048026, 2.6477354579837993, 1.8470395830227062 + # 5.036091582966037, 2.644472333951853, 1.8869528750656173 + + +if __name__ == "__main__": + import doctest + + doctest.testmod() + benchmark()