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
lower
cased characters of thesentence
. - The characters in the
set
are then iterated in a list comprehension. - The characters are filtered by an
if
isalpha()
statement, so that only alphabetic characters make it into the list. - The function returns whether the
len()
of thelist
is26
. If the number of unique letters in theset
is equal to the26
letters in the alphabet, then the function will returnTrue
.
13th Nov 2024
·
Found it useful?