Lets assume that you deal with a constant order of the data structure like the list you provided in your example.
If i understand well :
You got an input list of nested lists and some floats.
[ [ A, B, C, D ], somefloat, [A, B, C, D ] somefloat ]
And you try to get a list of nested lists which take the last element of the first nested list and combine it with the next float into a new nested list like so :
[ [D, somefloat], [D, somefloat] ]
One solution could be to use list comprehension, like so :
data=[[655.0, 48.77, 6.0, '1'], 0.0, [655.0, 48.77, 5.0, '1'], 1.0, [657.0, 49.25, 5.0, '4'], 2.2870067774276484, [657.0, 49.25, 1.0, '1'], 5.40651458890106, [657.0, 49.25, 1.0, '5'], 5.40651458890106]
newdata = [[data[i][-1], data[i +1]] for i in range(0, len(data), 2)]
print(newdata)
Output
[['1', 0.0], ['1', 1.0], ['4', 2.2870067774276484], ['1', 5.40651458890106], ['5', 5.40651458890106]]
Let's break it down :
for i in range(0, len(data), 2)
# will iterate through the first list, the range method here (starts from 0 to the length of the input list) will return the current index as "i" with step of two, for each iteration.
[data[i][-1]
#will take the current item (which is a nested list) and extract from it the last element, feel free to change the -1 by any index of the element you desire (if you decide to finally go with the third element, so change the -1 -which mean the last element- by 2 -which is the third element
data[i +1]
# will take the next element (which is the float number)
[data[i][-1], data[i +1]
# will put them in a nested list (feel free to use tuple or dict if you want to output another kind of nested data structure)
datayou want to extract and put innew. For your own purposes, feel free to use whatever spoken or written language you know best.