How do you print duplicate characters from a string? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How do you print duplicate characters from a string?

Hello friends answer my question

27th Apr 2021, 2:53 PM
PrakashRaj K
PrakashRaj K - avatar
5 Answers
+ 1
Can you explain little bit
27th Apr 2021, 2:56 PM
YUGRAJ
+ 4
Count each characters. If any letter is counted to 2 you print it out.
27th Apr 2021, 3:00 PM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 4
PrakashRaj K , to get help from the community, you should present us your attempt in your post. please put your code in playground, save it and link it here. thanks. here some hints how it could be done: # use input text and split it to individual characters. this result is a list # take this list and create a set from it (duplicates will be removed) # iterate through this set with a for loop # use the character given by the for loop and check if it appears more than 1 time in the list by using count() # if the given count is higher than 1, the character is duplicated - print it out #----- # instead of using a set, you can also use a dictionary. dictionary presreves the order of characters, set will not preserve the order #happy coding
27th Apr 2021, 5:49 PM
Lothar
Lothar - avatar
+ 3
declare a set now traverse the string from left to right letters by letters and insert each letter into the set. How to know duplicates letter? check if a letter is not inserted into a set that's means it's already there and hence a duplicate.
27th Apr 2021, 3:43 PM
Rohit
0
In python: You could iterate the data. Create a dict If the item is in the dict, set value +=1 else create the entry as key and set the value to 1. After this, proceed the entrys, which have a key > 1 (bc its a target item). There is a modul collections, which have a method counter or count. Take a look on the docs.
28th Apr 2021, 8:25 AM
Sven_m
Sven_m - avatar