Table of Contents
Introduction
The task is to find and print duplicate characters in the given 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
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.
0 Comments