Logic Building
# Take string input
s = input("Enter a string: ")
# Remove adjacent duplicates
result = ""
prev_char = None
for char in s:
if char != prev_char:
result += char
prev_char = char
print(f"Result: {result}")Output
Enter a string: aabbcc Result: abc
Track previous character and skip duplicates.
Key Concepts:
- Track previous character
- Add only if different from previous
- Removes adjacent duplicates