From 28bb13be37fff74924cb0ac2cd69590529ff371c Mon Sep 17 00:00:00 2001 From: fauzan171 Date: Sat, 6 Jun 2026 23:58:48 +0700 Subject: [PATCH] refactor(maths): use direct iteration instead of index-based loops in persistence.py Replace for i in range(len(numbers)) with for number in numbers in both multiplicative_persistence() and additive_persistence(). Direct iteration is more Pythonic and avoids unnecessary index lookups. --- maths/persistence.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/maths/persistence.py b/maths/persistence.py index c61a69a7c27d..6fee2e79fab9 100644 --- a/maths/persistence.py +++ b/maths/persistence.py @@ -28,8 +28,8 @@ def multiplicative_persistence(num: int) -> int: numbers = [int(i) for i in num_string] total = 1 - for i in range(len(numbers)): - total *= numbers[i] + for number in numbers: + total *= number num_string = str(total) @@ -67,8 +67,8 @@ def additive_persistence(num: int) -> int: numbers = [int(i) for i in num_string] total = 0 - for i in range(len(numbers)): - total += numbers[i] + for number in numbers: + total += number num_string = str(total)