I have a bunch of long lists (millions of elements long) that contain a time value and a temperature value ([time, temperature]). The lists look like this:
mylist = [[1, 72], [2, 75], [3, 74], [4, 75], [5, 74], [6, 75], [7, 79], [8, 71], [9, 79], [10, 71], [11, 75], [12, 74]]
What I want to do is get rid of consecutive pair duplicates. If a pair of temperatures are repeated consecutively, get rid of these duplicate elements (keeping only one).
That wording may be kind of confusing, so I'll provide an example using mylist:
mylist[0] and mylist[1] are consecutive pairs. Same with mylist[1] and mylist[2], and so on.
Moving on. Now, look at the temperature value from mylist. From mylist[0] all the way to mylist[11], the temperature values are:
72 75 74 75 74 75 79 71 79 71 75 74
In the above temperature values, you can see that a the pairs 75 74 as well as 79 71 are repeated in a consecutive fashion. What I want to do is just keep one pair, and get rid of the duplicates. So, the output I want is:
output = [[1, 72], [2, 75], [3, 74], [6, 75], [7, 79], [8, 71], [11, 75], [12, 74]]
Note: elements [11, 75] and [12, 74] are kept because although they also contain this 75 74 pattern, they aren't repeated consecutively, like from earlier in the list.
To try to solve this problem, I searched up and tried a bunch of things. The closest I got was by creating a solution using a for loop, where I'd check an element and the previous element (index-1), and then I'd check index-2 and index-3, and if they were determined to have temperature repeats, I'd delete two of the elements. Then, I'd repeat this looking in the forward direction (index+1). It kind of worked, but things got super messy and was extremely slow, and it turned my computer into a portbable heater. So, I was wondering if anyone knows how to efficiently and quickly way to get rid of these consecutive duplicate pairs.