Skip to content

S1Q3 · Pangram Check

⚡ Quick Reference

Function: is_pangram(text: str) -> bool

Core idea: collect all unique letters from the text (case-insensitive) and check if all 26 letters are present.

def is_pangram(text: str) -> bool:
    return set("abcdefghijklmnopqrstuvwxyz").issubset(set(text.lower()))

Key rules: - Case-insensitive → lowercase first - All 26 letters must appear at least once - Non-letter characters (spaces, punctuation) are ignored


Problem Statement

Problem

Write a function is_pangram(text) that returns True if text contains every letter of the alphabet at least once (case-insensitively).

Examples:

Input
"the quick brown fox jumps over the lazy dog"
Output
True
Input
"this is not a pangram"
Output
False

Solution approaches

def is_pangram(text: str) -> bool:
    return set("abcdefghijklmnopqrstuvwxyz").issubset(set(text.lower()))

set(text.lower()) collects all unique characters in the text. issubset checks if all 26 alphabet letters appear in it.

import string

def is_pangram(text: str) -> bool:
    return set(string.ascii_lowercase).issubset(set(text.lower()))

string.ascii_lowercase = "abcdefghijklmnopqrstuvwxyz" - avoids hardcoding the alphabet string.

def is_pangram(text: str) -> bool:
    text_lower = text.lower()
    for ch in "abcdefghijklmnopqrstuvwxyz":
        if ch not in text_lower:
            return False
    return True
def is_pangram(text: str) -> bool:
    text_lower = text.lower()
    return all(ch in text_lower for ch in "abcdefghijklmnopqrstuvwxyz")

all() short-circuits - returns False as soon as any letter is missing. Cleaner than an explicit loop.

is_pangram = lambda text: set("abcdefghijklmnopqrstuvwxyz") <= set(text.lower())

<= on sets is the subset operator - same as .issubset().


Key takeaways

01

set(text.lower()).issubset - clean and fast

Converting the text to a set of unique characters, then checking if the 26-letter alphabet is a subset, handles all cases in one expression. Non-letter characters are simply ignored since they won't affect the subset check.

02

A <= B is the same as A.issubset(B)

Python's set supports <= as the subset operator. set("abcdefghijklmnopqrstuvwxyz") <= set(text.lower()) is equivalent to issubset() - pick whichever reads more naturally.

03

all() short-circuits for efficiency

all(ch in text_lower for ch in alphabet) stops checking as soon as any letter is missing. For clearly non-pangram strings, this can return False much earlier than scanning the entire text.