Change language

Python program to check if a given string is a pangram

|

Examples :

  Input:  The quick brown fox jumps over the lazy dog ​​ Output:  Yes  Input:  abcdefgxyz  Output:  No 

We have already discussed the naive approach to checking pangrams in this article . Now let’s discuss a Pythonic approach to do the same.

Approach # 1: Pythonic Naive
This method uses a loop to check if each character in the string belongs to alphabet set or not.

# Python3 program for
# Check if the string is a pangram

import string

 

def ispangram ( str ):

alphabet = "abcdefghijklmnopqrstuvwxyz"

for char in alphabet:

  if char not in str . lower ():

  return False

  

return True

 
# Driver code

string = ’ the quick brown fox jumps over the lazy dog’

if (ispangram (string) = = True ):

print ( "Yes" )

else :

print ( "No" )

Exit:

 Yes 

Approach # 2 Using Python Set
Convert the given string to a set and then check if the alphabets are greater or equal or not. If the rowset is greater than or equal to, print "Yes", otherwise "No".

# Python3 program for
# Check if the string is a pangram

import string

 

alphabet = set (string.ascii_lowercase)

 

def ispangram (string):

return set (string.lower ( ))" = alphabet

  
# Driver code

string = " The quick brown fox jumps over the lazy dog ​​"

if (ispangram (string) = = True ):

  print ( "Yes" )

else :

print ( "No" )

Exit :

 Yes 

Approach # 3: An alternative to a given method
This is another method that is used uses the Python suite to determine if a string is a pangram or not. We compose a set of lowercase alphabets and a given string. If a set of a given string is subtracted from a set of alphabets, we know if the string is a pangram or not.

# Python3 program for
# Check if the string is a pangram

import string

 

alphabet = set (string.ascii_lowercase)

 

def ispangram ( str ):

return not set (alphabet) < / code> - set ( str )

 
# Driver code

string = ’the quick brown fox jumps over the lazy dog’

if (ispangram (string) = = True ):

print ( "Yes" )

else :

print ( "No" )

Output:

 Yes 

Approach # 4: ASCII method
Check if each character in the string is in the ASCII lowercase range, i.e. from 96 to 122.

# Python3 program for
# Check if the string is a pangram

import itertools

import string

  

alphabet = set (string.ascii_lowercase)

 

def ispangram ( str ):

return sum ( 1 for i in set ( str ) if 96 & lt;  ord (i) " = 122 ) = = 26

 
# Driver code

string = ’the quick brown fox jumps over the lazy dog’

if (ispangram (string) = = True ):

print ( "Yes" )

else :

print ( "No" )

Exit :

 Yes 

Python program to check if a given string is a pangram Python functions: Questions

Python program to check if a given string is a pangram String Variables: Questions

Shop

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method