Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # remove_consecutive_duplicates.py
- def remove_consecutive_duplicates(text):
- lines = text.split("\n") # Split the string into individual lines
- filtered_lines = [lines[i] for i in range(len(lines)) if i == 0 or lines[i] != lines[i-1]]
- return "\n".join(filtered_lines)
- test = '''\
- 1
- 2
- 3
- 3
- 3
- 4
- 3
- 5
- 5
- 6
- '''
- result = remove_consecutive_duplicates(test)
- print(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement