def tmax_time(tempL):
    lsol = []
    for time, tL in tempL:
        lsol.append( (time, max(tL)) )
    return lsol



def tmax_time_oven(ovenL, tempL):
    lsol = []
    for time, tL in tempL:
        tmax = max(tL)
        i = tL.index(tmax)
        lsol.append( (time, tmax, ovenL[i]) )
    return lsol

def tmax_time_oven(ovenL, tempL):
    lsol = []
    for time, tL in tempL:
        tmax, i = index_tmax(tL)
        lsol.append( (time, tmax, ovenL[i]) )
    return lsol

def index_tmax(tL):
    tmax = 0.0
    for i, v in enumerate(tL):
        if v > tmax:
            tmax = v
            imax = i
    return tmax, imax



def tmax_oven(ovenL, tempL):
    # INI
    temxL = [0.0]*len(ovenL)
    # BUILD
    for time, tL in tempL:
        update_txxL(tL, ovenL, temxL)
    # FI
    lsol = []
    for i in range(len(ovenL)):
        lsol.append( (ovenL[i], temxL[i]) )
    return lsol

def update_txxL(tL, ovenL, temxL):
    for i, t in enumerate(tL):
        if t > temxL[i]:
            temxL[i] = t



def tem_sel(lp, lt, tref):
    lsol = [] 
    for data, ltd in lt:
        tem_act(lsol, data, ltd, lp, tref)
    lsol.sort(reverse=True)
    return lsol

def tem_act(lsol, data, ltd, lp, tref):
    for i, t in enumerate(ltd):
        if t >= tref:
            lsol.append((t, lp[i], data))
'''
if __name__ == '__main__':
    import doctest
    doctest.testmod(verbose=True)
'''
