Apologies if this is already covered in another thread. I'm a bit new with Python (3, specifically), so perhaps the answer was given to a conceptually similar question and I missed the relevance.
I am looping through a list of lists, similar to the following:
biglist = [[a, b, x, d], [a, b, x, d], [a, b, y, d], [a, b, y, d], [a, b, z, d], [a, b, x, d]]
I would like to conditionally perform certain actions whenever the third element in a given sublist is different than the third element in the previous sublist. In the above example, this would happen for the third sublist (y != x), the fifth sublist (z != y) and the sixth sublist (x != z).
Whenever such non-matches occur, I would like to modify the corresponding first element in the current sublist. (Note - I know not to generally change a list while iterating through it, but I believe it is ok to modify other elements of a list of a list [as opposed to adding or removing entries]. For instance, in the above situation, I would like the loop to produce the following altered big list:
biglist = [[a, b, x, d], [a, b, x, d], [new_a, b, y, d], [a, b, y, d], [new_a, b, z, d], [new_a, b, x, d]]
After spending a few hours playing with an index and reading through other threads, I'm still stuck. Any help would be really appreciated.