Python set to check if string is panagram

Given a string, check if the given string is pangram or not.

Examples:

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



A normal way would have been to use frequency table and check if all elements were present or not. But using import ascii_lowercase as asc_lower we import all the lower characters in set and all characters of string in another set. In the function, two sets are formed- one for all lower case letters and one for the letters in the string. The two sets are subtracted and if it is an empty set, the string is a pangram.

Below is Python implementation of the above approach:

filter_none

edit
close

play_arrow

link
brightness_4
code

# import from string all ascii_lowercase and asc_lower
from string import ascii_lowercase as asc_lower
  
# function to check if all elements are present or not
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't a pangram")

chevron_right


Output:


The string is a pangram


My Personal Notes arrow_drop_up

Striver(underscore)79 at Codechef and codeforces D

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


2


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.