def is_pangram(sentence):
return len([ltr for ltr in set(sentence.lower()) if ltr.isalpha()]) \
== 26
- This approach first makes a set from the
lowercased characters of thesentence. - The characters in the
setare then iterated in a list comprehension. - The characters are filtered by an
ifisalpha()statement, so that only alphabetic characters make it into the list. - The function returns whether the
len()of thelistis26. If the number of unique letters in thesetis equal to the26letters in the alphabet, then the function will returnTrue.
4th Sep 2024
·
Found it useful?