Skip to content
scipython.com

Q4.2.1Determining if a string is a pangram

Write a one-line Python program to determine if a string is a pangram (contains each letter of the alphabet at least once).

Show solution

This can easily be achieved with a set. Given the string, s:

set(s.lower()) >= set('abcdefghijklmnopqrstuvwxyz')

is True if it is a pangram. For example,

>>> s = 'The quick brown fox jumps over the lazy dog'
>>> set(s.lower()) >= set('abcdefghijklmnopqrstuvwxyz')
True
>>> s = 'The quick brown fox jumped over the lazy dog'
>>> set(s.lower()) >= set('abcdefghijklmnopqrstuvwxyz')
False

That is, s is a pangram if the set of its letters is a superset of the set of all the letters in the alphebet.