Program to print duplicate characters in the string using Python

by | Mar 16, 2021 | Python Programs

Introduction

The task is to find and print duplicate characters in the given string.

Program to print duplicate characters in the string

Program

from collections import Counter




def duplicate_char(ip_str):

    ip_str = ip_str.lower()

    word_counter = Counter(ip_str)

    for key,value in word_counter.items():

        if value > 1:

            print(key)

           

ip_str =input("Enter the string: ")

print("The duplicate characters in the given string are:")

duplicate_char(ip_str)

 

Output

Program to print duplicate characters in the string Output

Explanation

In the above python code, we have used Counter() to get the key, value of characters present in the input string. We checked key and values for items and printed the key whose value is greater than 1. The key contains the unique characters and value contains the occurrence of characters.

Author

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.