Write a program to check if the given word is Isogram & Pair isogram in python

Carvia Tech | May 04, 2019 | 1 min read | 1,684 views | Python Coding Problems

An isogram is a word or phrase without a repeating letter.


An isogram (also known as a "nonpattern word") is a logological term for a word or phrase without a repeating letter. It is also used by some people to mean a word or phrase in which each letter appears the same number of times, not necessarily just once.

Examples include:

  1. uncopyrightables - 16 characters

  2. abolishment - 11 letters

  3. complaints, background, bankruptcy - 10 letters

We can write a simple program that checks if the given word is Isogram or not using the below logic:

  1. lowercase the input word

  2. remove all the duplicate characters using set and store the output in variable a

  3. get all the characters without removing duplicate into another variable b

  4. check if length of a and b is exactly the same i.e. it is an Isogram, else not.

Isogram: python implementation
def check_isogram(string):
    string = string.lower()
    a = [x for x in list(set(list(string))) if x != ' ']
    b = [x for x in list(string) if x != ' ']
    if len(a) == len(b):
        return string + " is an Isogram"
        return string + " is not an Isogram"
document is an Isogram

Pair Isograms

A pair isogram is a word where every letter appears exactly twice.

from collections import Counter

def check_pair_isogram(string):
    dict = Counter(list(string))
    dict_list = dict.values()
    if len(set(dict_list)) == 1:
        return string + " is pair Isogram"
        return string + " is NOT pair Isogram"


intestines is pair Isogram

Top articles in this category:
  1. Python coding challenges for interviews
  2. Flask Interview Questions
  3. Top 100 interview questions on Data Science & Machine Learning
  4. Google Data Scientist interview questions with answers
  5. Write a program for Hailstone Sequence in Python
  6. Find if credit card number is valid or not
  7. Write a python program to find Largest Substring that occurs more than once

Find more on this topic:
Machine Learning image
Machine Learning

Data science, machine learning, python, R, big data, spark, the Jupyter notebook, and much more

Last updated 1 week ago

Recommended books for interview preparation:

This website uses cookies to ensure you get the best experience on our website. more info