How to check whether a string is Pangram or not in Python
How to check whether a string is Pangram or not in Python
A pangram contains a sentence having each and every letter of the alphabet at least once. A pangram is used to display typefaces, test equipment, and develop skills in handwriting calligraphy. In English, there are can only be atleast 26 letters in the entire sentence. pangrams are used to make the computer coding easy and accurate. A pangram is used in all of the languages The words in a genuine pangram are often called as non-pattern words. Ex-Farmer jack realized that big yellow quilts were expensive.
STEP 1: This program takes a string and checks if it is a pangram or not. Take a string from the user and store it in a variable. and from the string library import lowercase letters.
STEP 2: Pass the string as a particular argument to the function in this step.
STEP 3: In this function, form two sets- one of all lower case letters and one of the letters in the string. and both are imported from the string library.
STEP 4: Subtract these two sets and check whether it is equal to an empty set or not.
STEP 5: Now using the if loop whether each alphabet exists in the string if it exists print the final result.
from string import ascii_lowercase as asc_lower # importing from the string library def check(s): # defining a function and passing string as an argument return set(asc_lower) - set(s.lower()) == set([]) strng=raw_input("Enter string:") if(check(strng)==True): print("The string is a pangram") else: print("The string isn't a pangram")
OUTPUT:
Enter string: The quick brown fox jumps over the lazy dog
The string is a pangram
Enter string: Hello world
The string isn't a pangram