How do you print duplicate characters from a string?
Hello friends answer my question
Can you explain little bit
Count each characters. If any letter is counted to 2 you print it out.
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
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.
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.