Open samp-suman opened 1 year ago
What you are doing in your code is removing the character no of count-1 times. Which is one of the approaches to solve this problem.
But if you want to maintain the order like-- abcabbdcdad
your output should be- abcd
. This will not be achieved by your approach.
Because .remove()
function will remove the very first character it matches.
For example after removing all duplicates of character 'a'
you will be left with-
"bcbbdcdad"
. It will only leave the last occurrence of 'a'
.
Other approach suggestions- go through the string character by character and store it in a list only if that character is not already in the list. something like this --
for i in string:
if i not in data:
dada.append(i)
I believe you Understood.
Happy Learning!!
I have written the code for removing duplicates Question. For input
AAAAAABHISHEK
answer is coming out correctly but if input is supposeAAAAABBHISHAAAAK
the order gets shuffled how to tackle that