set with issubset

全字母句
全字母句 在 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.

2026年09月23日 · 觉得有用?