From 215306d206641e4aa72ab5de97860690c8f8d695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=A3=D8=AD=D9=85=D8=AF=20=D8=A7=D9=84=D9=85=D8=AD=D9=85?= =?UTF-8?q?=D9=88=D8=AF=D9=8A=20=28Ahmed=20El-Mahmoudy=29?= Date: Wed, 11 Mar 2026 07:26:57 +0100 Subject: [PATCH] One liner to check that all columns in the line are numbers --- ch05-files/e18b2_sum_mult_columns.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/ch05-files/e18b2_sum_mult_columns.py b/ch05-files/e18b2_sum_mult_columns.py index f05e8f0..b64b397 100755 --- a/ch05-files/e18b2_sum_mult_columns.py +++ b/ch05-files/e18b2_sum_mult_columns.py @@ -13,12 +13,7 @@ def sum_mult_columns(filename): first, second = fields - if not first.isdigit(): - continue - - if not second.isdigit(): - continue - - total += int(first) * int(second) + if all(i.isdigit() for i in fields): + total += int(first) * int(second) return total