input: Write a python function to calculate the average grade for each student from a list of (name, grade) tuples.
  assert average_grades([('Bob', 80), ('John', 90), ('Bob', 70), ('John', 85)]) == {'Bob': 75.0, 'John': 87.5}
  assert average_grades([('Alice', 100), ('Alice', 90), ('Bob', 80)]) == {'Alice': 95.0, 'Bob': 80.0}
  assert average_grades([('Charlie', 60), ('Charlie', 40), ('Charlie', 80)]) == {'Charlie': 60.0}
output: def average_grades(grades):
      student_grades = {}
      for name, grade in grades:
          if name in student_grades:
              student_grades[name].append(grade)
          else:
              student_grades[name] = [grade]
      
      average_grades = {name: sum(grades) / len(grades) for name, grades in student_grades.items()}
      return average_grades