Given a string, create a new string with all the consecutive duplicates removed.
Hint: You may make a new string to store the result. You can check whether the current character and the next character are the same, then add that character to the new string.
Note: Only consecutive letters are removed not all duplicate occurences of a letter. You may try doing this alternative i.e. removing all duplicate letters from a given string, for your own practice.
s = input()
res = s[0]
for ch in s[1:]:
if ch != res[-1]:
res += ch
print(res)
Comments
Leave a comment