Created
February 5, 2026 14:36
-
-
Save epignatelli/a49192b2a2330f9c281ad8381dea9004 to your computer and use it in GitHub Desktop.
type_hinting.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def group_average(scores): | |
| """Compute the average score for each group. | |
| Args: | |
| scores: Records like {"group": str, "score": number}. Records with missing | |
| keys or invalid scores are ignored. | |
| Returns: | |
| Mapping from group name to average score. | |
| """ | |
| totals = {} | |
| counts = {} | |
| for row in scores: | |
| group = row.get("group") | |
| if not group: | |
| continue | |
| try: | |
| score = float(row.get("score")) | |
| except (TypeError, ValueError): | |
| continue | |
| totals[group] = totals.get(group, 0.0) + score | |
| counts[group] = counts.get(group, 0) + 1 | |
| return {g: totals[g] / counts[g] for g in totals} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment