I want find a record in a list of lists, on this case is the 3 and get the substract of their element [2] with the element [2] from their previous record
mylist = [
["acc", 2, 3.1,4.3,"pe"],
["fir", 1, 3.5,5.2,"p1"],
["sec", 3, 1.1,5.8,"pe"],
["set", 5, 6.2,6,2,"pa"],
["eve", 8, 5.4,5.7,"io"],
["ewa", 3, 4.1,4.1,"po"]
]
The result should be:
3.5 - 1.1 and 5.2 - 5.8
5.4 - 4.1 and 5.7 - 4.1
I can get it with this code, but I want learn some better and simpler way to do it, thanks.
i=0
while i<len(mylist)-1:
if mylist[i][1] == 3:
print mylist[i-1][2]-mylist[i][2]
print mylist[i-1][3]-mylist[i][3]
i+=1