Given a string, find all the duplicate characters which are similar to each others.
Let’s look at the example.
Input : hello Output : l Input : geeksforgeeeks Output : e g k s
We have discussed a solution in below post.
Print all the duplicates in the input string
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.
e g k s
- Python Counter| Find duplicate rows in a binary matrix
- Python Dictionary to find mirror characters in a string
- Python counter and dictionary intersection example (Make a string using deletion and rearrangement)
- Dictionary and counter in Python to find winner of election
- Python Counter to find the size of largest subset of anagram words
- Using Counter() in Python to find minimum character removal to make two strings anagram
- Python | Find keys with duplicate values in dictionary
- Python | Extract only characters from given string
- Iterate over characters of a string in Python
- Python | Convert a list of characters into a string
- Python | Splitting string to list of characters
- Python | Split string into list of characters
- Python | Return lowercase characters from given string
- Concatenated string with uncommon characters in Python
- Check if both halves of the string have same set of characters in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.