close

How do I check if a string contains ALL letters of the alphabet in python?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How do I check if a string contains ALL letters of the alphabet in python in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How do I check if a string contains ALL letters of the alphabet in python?

  1. How do I check if a string contains ALL letters of the alphabet in python?

    Only if every letter of the alphabet is in the set created from the input text will it be a superset; by using a superset and not equality, you allow for punctuation, digits and whitespace, in addition to the (ASCII) letters.

  2. check if a string contains ALL letters of the alphabet in python

    Only if every letter of the alphabet is in the set created from the input text will it be a superset; by using a superset and not equality, you allow for punctuation, digits and whitespace, in addition to the (ASCII) letters.

Method 1

This is not something I’d solve with a regular expression, no. Create a set of the lowercased string and check if it is a superset of the letters of the alphabet:

import string

alphabet = set(string.ascii_lowercase)

def ispangram(input_string):
    return set(input_string.lower()) >= alphabet

Only if every letter of the alphabet is in the set created from the input text will it be a superset; by using a superset and not equality, you allow for punctuation, digits and whitespace, in addition to the (ASCII) letters.

Demo:

>>> import string
>>> alphabet = set(string.ascii_lowercase)
>>> input_string = 'We promptly judged antique ivory buckles for the next prize'
>>> set(input_string.lower()) >= alphabet
True
>>> set(input_string[:15].lower()) >= alphabet
False

Method 2

This is my solution in python:

alphabet = "abcdefghijklmnopqrstuvwxyz"
sentence = input()
sentence = sentence.lower()
missing = ''
for letter in alphabet:
  if letter not in sentence:
    missing = missing+letter
if (len(missing) != 0):
  print("missing", missing)
else:
  print("pangram")

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read