Removing all duplicates characters from a given string.

According to the heading, the resultant string consists of unique characters.

for example:-

input string –>

1 .”rama”

2 . “ramu”

3. “rrrr”

Resultant string –>

1 . “ram”

2. “ramu”

3. “r”

input_string = "rama"
resultant_string = ""
print("String before removing duplicate string is -->", input_string)
print()
for each_letter in input_string:
    if each_letter not in resultant_string:
        resultant_string = resultant_string + each_letter
print("After removing duplicate character from input the resultant string is -->", resultant_string)
        
Output:
String before removing duplicate string is --> rama

After removing duplicate character from input the resultant string is --> ram

Explanation:-

step 1:- Initializing input string

step 1:- Initializing input string

step 2:- taking each character from the input string and check if this character is present in the resultant string or not. If it is not present we will add them to the resultant string. By doing this, my resultant string will contain only unique characters from the input string.

step 4:- Display the resultant string.

Excercise:

Write a program to print only repeating characters from a string.

input string --> "rama"
output string --> "a"

Send solution at "contribute.articles@tech-bloggers.in"

Leave a Comment

Your email address will not be published. Required fields are marked *

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock