Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Remove all Adjacent duplicates using a loop
def adjacent_similar_chars(answer): new_answer = "" ch_last = "" start, end = 0, 0 for index, ch in enumerate(answer): if index: if ch == ch_last: end = index else: if start == end: new_answer = new_answer + ch_last start, end = index, index else: start, end = index, index ch_last = ch if start == end: new_answer = new_answer + ch_last return new_answer # START if __name__ == "__main__": # INPUT 1 answer = input("Enter a string: ") # abbabd print(adjacent_similar_chars(answer)) # aabd # INPUT 2 answer = input("Enter a string: ") # abcddddeefffghii print(adjacent_similar_chars(answer)) # abcgh # INPUT 3 answer = input("Enter a string: ") # abcddddeefffghi print(adjacent_similar_chars(answer)) # abcgh # INPUT 4 answer = input("Enter a string: ") # aa**mmmxxnnnnRaaI++SH((IKES))H print(adjacent_similar_chars(answer)) #
run
|
edit
|
history
|
help
0
LinkedList implementation
количество 1 и 0 в последовательности чисел до n
Arithmetic Operations
Square numbers
Faiha Lesson 4
Python wtf ?
😚😚😚
10 25 58
Exception.py
ванечка с тебя 200 рублей, жду мой сладкий 🤑