Created
June 30, 2025 18:43
-
-
Save JessicaWachtel/ee7f77b7b7d6c86e9b0bf660ae14c907 to your computer and use it in GitHub Desktop.
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
| import json | |
| from collections import defaultdict | |
| def f1(path): | |
| with open(path, 'r') as f: | |
| return json.load(f) | |
| def f2(items): | |
| result = defaultdict(list) | |
| for i in items: | |
| k = i.get('category', 'Unknown') | |
| result[k].append(i) | |
| return result | |
| def f3(d): | |
| out = {} | |
| for k, v in d.items(): | |
| s = sum(x['value'] for x in v) | |
| m = s / len(v) | |
| out[k] = m | |
| return out | |
| def runner(): | |
| data = f1('data.json') | |
| grouped = f2(data) | |
| stats = f3(grouped) | |
| for k, v in stats.items(): | |
| print(f"{k}: {v:.2f}") | |
| if __name__ == '__main__': | |
| runner() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@JessicaWachtel @JessicaWachtel what's this?