From cd8dfb74a4d60b257fa86eaed1ff54fb65cc1057 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Mon, 27 May 2024 10:13:24 +0200 Subject: [PATCH] Use defaultdict, not Counter for travel distances --- agenda/types.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/agenda/types.py b/agenda/types.py index 1b4a27a..0e5bfc4 100644 --- a/agenda/types.py +++ b/agenda/types.py @@ -3,7 +3,7 @@ import collections import datetime import typing -from collections import Counter +from collections import defaultdict from dataclasses import dataclass, field import emoji @@ -190,12 +190,12 @@ class Trip: Any travel item with a missing or None 'distance' field is ignored. """ - transport_distances: Counter[float] = Counter() + transport_distances: defaultdict[str, float] = defaultdict(float) for item in self.travel: distance = item.get("distance") if distance: - transport_type = item.get("type", "unknown") + transport_type: str = item.get("type", "unknown") transport_distances[transport_type] += distance return list(transport_distances.items())