I have this string:
strg = "01|15|59, 1|47|16, 01|17|20, 1|32|34, 2|17|17"
#they are hours, minutes, seconds for different results
I will proceed by creating a list of sub-lists in which the first element is a list of h,m,s and the second element is the amount of total seconds. This is the code:
def stat(strg):
z = strg.split(",") #creates the lists with h,m,s
x = [i.split('|') for i in z] #remove the "|"
y = [[int(i) for i in q] for q in x] #transform the list elements into integers
w = [] #ready the new list (of lists)
for i in range(0, len(y)): #for lopp to fill "w"
k = []
z = ((y[i][0]*3600)+(y[i][1]*60)+y[i][2]) #transforms into total seconds amount
k.append(y[i])
k.append(z)
w.append(k)
return max(w)
The result will be:
[[2, 17, 17], 8237]
(FYI, without max, "return w" will bring:)
[[[1, 15, 59], 4559], [[1, 47, 16], 6436], [[1, 17, 20], 4640], [[1, 32, 34], 5554], [[2, 17, 17], 8237]]
Now my questions are:
1: How is the max() function working in this case? Which value has the programme considered?
2: Suppose we have a random number instead of the total amount of seconds as second element for each sub-list, how would I be able choose the sub-list with the max random value?