Skip to content

Commit 49c9975

Browse files
authored
Add pangram checker logic building problem
This module includes a function to check if a string is a pangram, with examples provided in the docstring.
1 parent 074a3f3 commit 49c9975

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

logic_building_problems/pangram.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""Pangram Checker.
2+
3+
This module contains functions to check if a string is a pangram.
4+
A pangram is a sentence that contains every letter of the alphabet at least once.
5+
"""
6+
7+
import string
8+
9+
10+
def is_pangram(text: str) -> bool:
11+
"""
12+
Check if a given string is a pangram.
13+
14+
A pangram is a string that contains every letter of the alphabet
15+
at least once, ignoring case and non-alphabetic characters.
16+
17+
Args:
18+
text: The string to check
19+
20+
Returns:
21+
True if the string is a pangram, False otherwise
22+
23+
Examples:
24+
>>> is_pangram("The quick brown fox jumps over the lazy dog")
25+
True
26+
>>> is_pangram("Hello World")
27+
False
28+
>>> is_pangram("Pack my box with five dozen liquor jugs")
29+
True
30+
>>> is_pangram("abcdefghijklmnopqrstuvwxyz")
31+
True
32+
>>> is_pangram("")
33+
False
34+
>>> is_pangram("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
35+
True
36+
"""
37+
# Convert text to lowercase and get all unique letters
38+
letters = set(char.lower() for char in text if char.isalpha())
39+
# Check if all 26 letters of the alphabet are present
40+
return len(letters) == 26
41+
42+
43+
if __name__ == "__main__":
44+
import doctest
45+
46+
doctest.testmod()

0 commit comments

Comments
 (0)