diff --git a/pangram/pangram.py b/pangram/pangram.py index 5377191..3b97811 100644 --- a/pangram/pangram.py +++ b/pangram/pangram.py @@ -1,2 +1,31 @@ -def is_pangram(sentence): - pass +""" +Pangram. + +You work for a company that sells fonts through their website. They'd like to +show a different sentence each time someone views a font on their website. +To give a comprehensive sense of the font, the random sentences should use +all the letters in the English alphabet. + +They're running a competition to get suggestions for sentences that they can +use. You're in charge of checking the submissions to see if they are valid. +""" + + +def is_pangram(sentence: str) -> bool: + """ + Verify that the random sentences uses all the letters in the English. + + :param sentence: The sentence to check for pangram validity + :type sentence: str + :return: True if the sentence contains all 26 letters of the English, + False otherwise + :rtype: bool + """ + # Empty string + if not sentence: + return False + # Convert sentence to lowercase and extract unique alphabetic characters + unique_letters: set = set( + char for char in sentence.lower() if char.isalpha() + ) + return len(unique_letters) == 26 diff --git a/pangram/pangram_test.py b/pangram/pangram_test.py index 09e303d..83740a6 100644 --- a/pangram/pangram_test.py +++ b/pangram/pangram_test.py @@ -1,3 +1,5 @@ +# pylint: disable=C0114, C0115, C0116, R0904 + # These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/pangram/canonical-data.json # File last updated on 2023-07-19 diff --git a/solutions/python/pangram/1/pangram.py b/solutions/python/pangram/1/pangram.py new file mode 100644 index 0000000..5377191 --- /dev/null +++ b/solutions/python/pangram/1/pangram.py @@ -0,0 +1,2 @@ +def is_pangram(sentence): + pass diff --git a/solutions/python/pangram/2/pangram.py b/solutions/python/pangram/2/pangram.py new file mode 100644 index 0000000..e5e8164 --- /dev/null +++ b/solutions/python/pangram/2/pangram.py @@ -0,0 +1,28 @@ +""" +Pangram. + +You work for a company that sells fonts through their website. They'd like to show a +different sentence each time someone views a font on their website. To give a +comprehensive sense of the font, the random sentences should use all the letters +in the English alphabet. + +They're running a competition to get suggestions for sentences that they can use. +You're in charge of checking the submissions to see if they are valid. +""" +import string + +letters: str = string.ascii_lowercase + + +def is_pangram(sentence: str) -> bool: + """ + Verify that the random sentences uses all the letters in the English alphabet. + + :param sentence: The sentence to check for pangram validity + :type sentence: str + :return: True if the sentence contains all 26 letters of the English alphabet, False otherwise + :rtype: bool + """ + # Convert sentence to lowercase and extract unique alphabetic characters + unique_letters: set = set( char for char in sentence.lower() if char.isalpha()) + return all(char in letters for char in unique_letters)