Only Groups You Can Trust

Data with PythonMedium+10 XP+10

Only Groups You Can Trust

In the wine data, the very best and very worst scores have only a handful of wines, so their averages are shaky. A careful analyst only reports a score's average when enough wines got that score.

Task: write alcohol_by_score(scores, alcohol, min_wines). Wine i got quality score scores[i] and has alcohol level alcohol[i].

Return a dictionary mapping each score to the average alcohol of the wines with that score, rounded to 2 decimal places. Leave out any score that fewer than min_wines wines got.

  • Scores are whole numbers. Keep them as whole-number keys.
  • If no score has enough wines, return {}.

Examples

scores = [5, 6, 5, 8, 6, 5]
alcohol = [9.4, 10.2, 9.8, 12.5, 11.0, 9.6]
min_wines = 2
returns {5: 9.6, 6: 10.6}
scores = [3, 7]
alcohol = [8.4, 12.0]
min_wines = 2
returns {}

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run