Program to check whether the sentence is pangram or not using Python

Suppose we have a sentence s with only lowercase English letters. We have to check whether it is a pangram or not? A string is said to be pangram if it contains all 26 letters present in English alphabet.

So, if the input is like s = "thegrumpywizardmakestoxicbrewfortheevilqueenandjack", then the output will be True as there are 26 letters from a to z.

To solve this, we will follow these steps −

  • dictb := a new map

  • for each i in s, do

    • dictb[i] := (if i is present in dictb[i], then i, otherwise 0) + 1

  • if size of dictb is same as 26, then

    • return True

  • return False

Let us see the following implementation to get better understanding −


 Live Demo

def solve(s):
   dictb = {}
   for i in s:
      dictb[i] = dictb.get(i,0) + 1
   if len(dictb) == 26:
      return True
   return False
s = "thegrumpywizardmakestoxicbrewfortheevilqueenandjack"