I'm trying to remove duplicates in a string upon user input. Here''s my code:
userinput = input("Enter a word:")
def duplicates_removal(x):
for i in range(len(x)-1):
if x[i] == x[i +1]:
return duplicates_removal(x.replace(x[i], ' '))
return x
print(duplicates_removal(userInput))
When I run the code, and input the string Bananas, it produces the output Bananas with the duplicates not removed. Is there any flaws in the code? Also I prefer not using built in functions for this since I just started learning on string manipulation.
Input: Bananas
Output desired: Bans