def is_pangram(sentence):
return len(set(ltr for ltr in sentence.lower() if ltr.isalpha())) == 26
- This approach first makes a set from the
lowercased characters of thesentence. - The characters are filtered using a set comprehension with an
ifisalpha()statement, so that only alphabetic characters make it into the set. - The function returns whether the
len()of thesetis26. If the number of unique ASCII (American Standard Code for Information Interchange) letters in thesetis equal to the26letters in the ASCII alphabet, then the function will returnTrue. - This approach is efficient because it uses a set to eliminate duplicates and directly checks the length, which is a constant time operation.
23rd Sep 2026
·
Found it useful?