def gen_goal_stats(Dplayers, Dresults, team):
    Dgoals = {}
    if team in Dplayers:
        for match, Lgoals in Dresults.items():
            t1, t2 = match
            if team == t1:
                update_Dgoals(Lgoals, t2, Dplayers, team, Dgoals)
            elif team == t2:
                update_Dgoals(Lgoals, t1, Dplayers, team, Dgoals)
            else:
                pass
    return Dgoals

def update_Dgoals(Lgoals, opteam, Dplayers, team, Dgoals):
    for minute, scorer in Lgoals:
        if scorer in Dplayers[team]:
            value = (opteam, minute)
            if scorer not in Dgoals:
                Dgoals[scorer] = [value]
            else:
                Dgoals[scorer].append(value)

def sort_by_minute(Dgoals):
    for Lgoals in Dgoals.values():
        Lgoals.sort(reverse=True, key=lambda x: x[1]) 
            
