# Task
 "AL-AHLY" and "Zamalek" are the best teams in Egypt, but "AL-AHLY" always wins the matches between them. "Zamalek" managers want to know what is the best match they've played so far.
 
 The best match is the match they lost with the minimum goal difference. If there is more than one match with the same difference, choose the one "Zamalek" scored more goals in.
 
 Given the information about all matches they played, return the `index` of the best match (`0-based`). If more than one valid result, return the smallest index.

# Example

 For `ALAHLYGoals = [6,4] and zamalekGoals = [1,2]`, the output should be 1.
 
 Because `4 - 2` is less than `6 - 1`
 
 For `ALAHLYGoals = [1,2,3,4,5] and zamalekGoals = [0,1,2,3,4]`, the output should be 4.
 
 The goal difference of all matches are 1, but at 4th match "Zamalek" scored more goals in. So the result is `4`.
 
# Input/Output


 -  `[input]` integer array `ALAHLYGoals`

  The number of goals "AL-AHLY" scored in each match.


 - `[input]` integer array `zamalekGoals`

  The number of goals "Zamalek" scored in each match. It is guaranteed that zamalekGoals[i] < ALAHLYGoals[i] for each element.


 - `[output]` an integer

  Index of the best match.

Difficulty: introductory

Starter code:

def best_match(goals1, goals2):
	

Solutions:
def best_match(goals1, goals2):
    return min( (a-b, -b, i) for i,(a,b) in enumerate(zip(goals1, goals2)) )[2]

def best_match(goals1, goals2):
  bestDiff = goals1[0] - goals2[0]
  bestIndex = 0
  for i in range(len(goals1)):
      if goals1[i] - goals2[i] < bestDiff:
          bestIndex = i
          bestDiff = goals1[i] - goals2[i]
      if (goals1[i] - goals2[i] == bestDiff) and (goals2[i] > goals2[bestIndex]):
          bestIndex = i
          bestDiff = goals1[i] - goals2[i]
  return bestIndex

def best_match(goals1, goals2):
    return sorted( (a-b, -b, i) for i,(a,b) in enumerate(zip(goals1, goals2)) )[0][2]


def best_match(goals1 : list, goals2 : list):

    # Set the current "best" values as the first match
    lowest_difference = goals1[0] - goals2[0]
    amount_of_goals = goals2[0]
    best_match_index = 0

    # Loop through the length of the lists, to see if theres a better match
    for i in range(1, len(goals1)):

        # The current difference in goals.
        current_difference = goals1[i] - goals2[i]

        if (current_difference) < lowest_difference: # If the game was closer, this is the best match
            lowest_difference = current_difference
            amount_of_goals = goals2[i]
            best_match_index = i

        elif (current_difference == lowest_difference) and (amount_of_goals < goals2[i]): # If the difference is the same, but Zamalek scored more goals, it should change the best match.
            amount_of_goals = goals2[i]
            best_match_index = i
    
    return best_match_index

def best_match(goals1, goals2):
  # scores makes an array of following structure [(Goal difference, Zamalek Goals, index in the arrays), ...]
  scores = [(zip[0] - zip[1], zip[1], idx) for idx, zip in enumerate(zip(goals1, goals2))]
  # Sorts the score array first by Goal difference first and by Zamalek Goals after (reversed) and get's the first element index
  return sorted(scores, key=lambda y: (y[0], -y[1]))[0][2]

from collections import namedtuple


def best_match(goals1, goals2):
    Match = namedtuple('Match', ['diff', 'scored', 'index'])
    temp = [Match(xy[0]-xy[1], xy[1], idx) for idx, xy in enumerate(zip(goals1, goals2))]
    best_diff = min([match.diff for match in temp])
    temp = [match for match in temp if match.diff == best_diff]
    return sorted(temp, key=lambda match: match.scored, reverse=True)[0].index

def best_match(goals1, goals2):
    num=goals1[0]-goals2[0]
    goal=0
    for i in range(len(goals1)):
        if goals1[i]-goals2[i]<num:
            num=goals1[i]-goals2[i]
            goal=i
        if goals1[i]-goals2[i]==num:
            if goals2[i]>goals2[goal]:
                goal=i
    return goal
            
  #coding and coding..


def best_match(goals1, goals2):
    l = [abs(i - j) for i, j in zip(goals1, goals2)]
    ll = [(abs(i - j), j) for i, j in zip(goals1, goals2)]
    if l.count(min(l)) > 1:
        l_new = [(a, b) for a, b in sorted(ll) if a == min(l)]
        return ll.index(l_new[-1])
    return l.index(min(l))

def best_match(goals1, goals2):
    l = [(i - j, -j) for i, j in zip(goals1, goals2)]
    return l.index(min(l))