Q:

How to remove an entry in a list based on a value in the sublist

I have a list as below:
list = [ [1,2,3,4,5], 
         [1,2,3,3,5], 
         [1,2,3,2,5], 
         [1,2,3,4,6] ]

I would like to parse through this list and remove the entry if it satisfy below conditions:

if list[i][0] is the same as list[i+1][0] AND
if list[i][4] is the same as list[i+1][4]

which will result in below list:
list = [ [1,2,3,4,5],
         [1,2,3,4,6]]

Any help is much appreciated. Thanks.
Edit: Using Python 2.5.4

A:

Use a list comprehension to keep everything not matching the condition:
[sublist for i, sublist in enumerate(yourlist)
    if i + 1 == len(yourlist) or (sublist[0], sublist[4]) != (yourlist[i+1][0], yourlist[i + 1][4])]

So, any row that is either the last one, or one where the first and last element do not match the same columns in the next row is allowed.
Result:
>>> [sublist for i, sublist in enumerate(yourlist)
...     if i + 1 == len(yourlist) or (sublist[0], sublist[4]) != (yourlist[i+1][0], yourlist[i + 1][4])]
[[1, 2, 3, 2, 5], [1, 2, 3, 4, 6]]

