set with issubset

Pangram in Python
from string import ascii_lowercase

ALPHABET = set(ascii_lowercase)

def is_pangram(sentence):
    return ALPHABET.issubset(sentence.lower())

In this approach a set is made from the ascii_lowercase letters, and another set is made from the lowercased letters in the sentence.

The function returns if the alphabet set issubset() of the sentence set. If all of the letters in the alphabet are a subset of the letters in the sentence, then the function will return True.

22nd May 2024 · Found it useful?