Hackbright Code Challenges

Pangram: Solution

Pangram: Solution

Problem

Pangram

Whiteboard

Easier

Challenge

Easier

Concepts

Sets, Strings

Download

pangram-solution.zip


We can make a set of the used letters which are alphabetical, and then see if that includes 26 entries (remember, sets don’t store duplicates).

We use a “set comprehension” to build this. We could have made an empty set and put each letter in individually, but just like list comprehensions, set comprehensions are easy to write and understand.

pangram.py
def is_pangram(sentence):
    """Given a string, return True if it is a pangram, False otherwise."""

    # START SOLUTION

    used = {char.lower() for char in sentence if char.isalpha()}
    return len(used) == 26