def tcf_genera(Lr):
    Dt = {}
    for e1, e2, g1, g2 in Lr:
        act_trajectoria(Dt, e1, e2, g1, g2)
        act_trajectoria(Dt, e2, e1, g2, g1)
    return Dt

def act_trajectoria(Dt, e1, e2, g1, g2):
    if e1 not in Dt:
        Dt[e1] = [(e2, g1, g2)]
    else:
        Dt[e1].append((e2, g1, g2))
        
def tcf_puntua(Dt):
    for c in Dt:
        lsol = calc_punts_gols(Dt[c])
        lsol.append(Dt[c])
        Dt[c] = lsol
        
def calc_punts_gols(Lp):
    p = tgf = tgc = 0
    for e, gf, gc in Lp:
        if gf > gc:
            p += 3
        elif gf == gc:
            p += 1
        tgf += gf
        tgc += gc
    return([p, tgf, tgc])
