Given a string, find all the duplicate characters which are similar to each others.
Let’s look at the example.
Examples:
Input : hello
Output : l
Input : geeksforgeeeks
Output : e g k s
We can solve this problem quickly using python Counter() method. Approach is very simple.
1) First create a dictionary using Counter method having strings as keys and their frequencies as values.
2) Declare a temp variable.
3) Print all the indexes from the keys which have value greater than 1.
from collections import Counter def find_dup_char(input): # now create dictionary using counter method # which will have strings as key and their # frequencies as value WC = Counter(input) j = -1 # Finding no. of occurrence of a character # and get the index of it. for i in WC.values(): j = j + 1 if( i > 1 ): print WC.keys()[j], # Driver program if __name__ == "__main__": input = 'geeksforgeeks' find_dup_char(input)
Output:
e g k s
Australia
UK
UAE
Singapore
Canada
New
Zealand
Malaysia
USA
India
South
Africa
Ireland
Saudi
Arab
Qatar
Kuwait
Hongkong
Copyright 2016-2023 www.programmingshark.com - All Rights Reserved.
Disclaimer : Any type of help and guidance service given by us is just for reference purpose. We never ask any of our clients to submit our solution guide as it is, anywhere.