Python set to test if a string is a panagram

Python Methods and Functions | String Variables


 Input: The quick brown fox jumps over the lazy dog ​​Output: The string is a pangram Input: geeks for geeks Output: The string is not pangram 

The usual way would be to use a frequency table and check if all elements were present or not. But by using import ascii_lowercase as asc_lower we import all the lower characters in the set and all the string characters in the other set. In the function, two sets of — one for all lowercase letters and one for letters in the line. The two sets are subtracted, and if it is an empty set, the string is a pangram.

Below is the Python implementation of the above approach:

# import from string all ascii_lowercase and asc_lower

from string import ascii_lowercase as asc_lower

# function to check the presence or absence of all elements

def check (s):

return set (asc_lower) - set (s.lower ()) = = set ([])

# driver code

strng = "The quick brown fox jumps over the lazy dog"

if (check (strng) = = True  ):

print ( "The string is a pangram" )

else :

print ( "The string isn'ta pangram" )


 The string is a pangram