From a131ef471503387a1840eceec308fa3c88d06137 Mon Sep 17 00:00:00 2001 From: aaron Date: Sat, 2 Dec 2023 00:23:42 +0100 Subject: [PATCH] improva part a --- 1/trebuchet.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/1/trebuchet.py b/1/trebuchet.py index 9d5db6d..1012870 100644 --- a/1/trebuchet.py +++ b/1/trebuchet.py @@ -6,8 +6,10 @@ def calibrate(data: list) -> int: """ Solve part a. """ - n = "".join(c for c in data if c.isdigit()) - return int(n[0] + n[-1]) + # filter digits + digits = [c for c in data if c.isdigit()] + # return the sum of the first and the last digit + return int(digits[0] + digits[-1]) def translate(s: str) -> str: