def gen_Dscorers(Dmatches):
    Dscorers = {}
    for match in Dmatches:
        Lgoals_comp(Dscorers, Dmatches[match], match)
    return Dscorers

def Lgoals_comp(Dscorers, Lgoals, match):
    for goal in Lgoals:
        goal_comp(Dscorers, goal, match)
            
def goal_comp(D, goal, match):
    name, m, es_pen = goal
    if name not in D:
        if not es_pen:
            D[name] = [1, 0, [match]]
        else:
            D[name] = [1, 1, [match]]
    else: # El jugador name ja havia marcat abans.
        D[name][0] += 1
        if es_pen:
            D[name][1] += 1
        D[name][2].append(match)

def sort_Dscorers(D):
    L = sorted(D.items())
    L.sort(key=lambda x: (-x[1][0]+x[1][1], -x[1][0]))
    Lsol = []
    for j in L:
        Lsol.append(j[0]) 
    return Lsol
