I have a list containing many subscriptions. i.e.
mylst = [[1, 343, 407, 433, 27],
[1, 344, 413, 744, 302],
[1, 344, 500, 600, 100],
[1, 344, 752, 1114, 363],
[1, 345, 755, 922, 168],
[2, 345, 188, 1093, 906],
[2, 346, 4, 950, 947],
[2, 346, 953, 995, 43],
[3, 346, 967, 1084, 118],
[3, 347, 4, 951, 948],
[3, 347, 1053, 1086, 34],
[3, 349, 1049, 1125, 77],
[3, 349, 1004, 1124, 120],
[3, 350, 185, 986, 802],
[3, 352, 1018, 1055, 38]]
I want to first classify this list and make another list using three steps. First of all, I want to compare the sublist when the first element in each sublist is the same, i.e. Mylist [a] [0] == 1. Secondly, comparing the second element in the sublist and if the difference between the second element in the sublist and the other second element in the following sulbists is up to 2, then calculate the difference between the third elements or fourth elements. If any difference for the third and fourth elements is less than 10, I want to add a subscription index.
The result I want should be ... as follows: [0, 1, 3, 4, 6, 7, 10, 11, 12]
The following are my naive attempts to do this.
The following are my naive attempts to do this.
def seg(mylist) :
Segments = []
for a in range(len(mylist)-1) :
for index, value in enumerate (mylist) :
if mylist[a][0] == 1 :
if abs(mylist[a][1] - mylist[a+1][1]) <= 2 :
if (abs(mylist[a][2] - mylist[a+1][2]) <= 10 or
abs(mylist[a][3] - mylist[a+1][3]) <= 10) :
Segments.append(index)
return Segments
or
def seg(mylist) :
Segments= []
for index, value in enumerate(mylist) :
for a in range(len(mylist)-1) :
if mylist[a][0] == 1 :
try :
if abs(mylist[a][1]-mylist[a+1][1]) <= 2 :
if (abs(mylist[a][2]-mylist[a+1][2]) <= 10 or
abs(mylist[a][3] - mylist[a+1][3]) <= 10) :
Segments.append(index)
except IndexError :
if abs(mylist[a][1]-mylist[a+1][1]) <= 2 :
if (abs(mylist[a][2]-mylist[a+1][2]) <= 10 or
abs(mylist[a][3] - mylist[a+1][3]) <= 10):
Segments.append(index)
return Segments
, , . , try , ( ), while, 'for'.
, , ? , "" ?
, .