40. Pangram
A pangram is a sentence that uses every letter of the alphabet at least once, like "The quick brown fox jumps over the lazy dog". Typists use them to try out every key.
Write a function is_pangram(sentence) that takes a string and returns True if every letter from a to z
appears in it at least once, or False if any letter is missing.
- Ignore case:
Aandaare the same letter. - Other characters (spaces, digits, punctuation) don't matter either way.
- An empty sentence uses no letters, so it isn't a pangram.
Example 1
sentence = "Sphinx of black quartz, judge my vow"TrueExample 2
sentence = "abcdefghijklmnopqrstuvwxy"FalseConstraints
sentencehas 0 to 200 characters: English letters, digits, spaces and punctuation.
Submit also runs 7 more tests you can't see.
Practises Sets (lesson 12).
set(text)keeps each character oftextonce:set("noon")is{"n", "o"}. Make the sentence lower case first, soAandacount as one.- Write the alphabet as a set too:
set("abcdefghijklmnopqrstuvwxyz"). alphabet <= lettersisTruewhen every item ofalphabetis inletters(a subset). Counting the set's size doesn't work: spaces and commas would count too.
Solve it without hints for 3 stars, with hints for 2, after seeing the solution for 1.
One way to solve it, once you've had a go.
Solving it after seeing the solution earns 1 star.
Your Submits show here, with their code, so you can go back to one. They stay in this browser.
def is_pangram(sentence):
"""Check whether sentence uses every letter a to z.
sentence: str, any text; may be empty
Returns: bool, True if all 26 letters appear (in any
case), else False
"""
# Write your code here
pass
Run your code to see how it does on the test cases, or Submit to check every test.