Given list of elements, remove alternate consecutive duplicates of elements.
Input : test_list = [5, 5, 5, 5, 6, 6]
Output : [5, 5, 6]
Explanation : Alternate occ. of 5 and 6 are removed.
Input : test_list = [5, 5, 5, 5]
Output : [5, 5]
Explanation : Alternate occ. of 5 are removed.
Method : Using loop + remove()
The combination of above functions can be used to solve this problem. In this, we iterate each element and use additional previous element variable to keep track of alternate criteria. The removal is performed using remove().
The original list : [5, 5, 5, 5, 6, 6, 8, 3, 3, 8] List after alternate duplicates removal : [5, 5, 6, 8, 3, 8]
- Python groupby method to remove all consecutive duplicates
- Python | Remove consecutive duplicates from list
- Python | Consecutive duplicates all elements deletion in list
- Python - Ways to print longest consecutive list without considering duplicates element
- Remove all duplicates from a given string in Python
- Python Remove Duplicates from a List
- Python | Remove all duplicates words from a given sentence
- Python - Ways to remove duplicates from list
- Python | Remove all duplicates and permutations in nested list
- Python | Remove duplicates from nested list
- Python | Sort given list by frequency and remove duplicates
- Python | Remove duplicates in Matrix
- Python | Remove duplicates based on Kth element tuple list
- Python - Remove Equilength and Equisum Tuple Duplicates
- Python - Remove Kth Index Duplicates in Tuple
- Python - Remove K length Duplicates from String
- Python | Remove Consecutive tuple according to key
- Python - Remove Consecutive K element records
- Python | List consisting of all the alternate elements
- Python | List Initialization with alternate 0s and 1s
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.