replace index-based for loop with iteration through zip

This commit is contained in:
Heiko Ludwig 2024-12-03 19:56:04 +01:00
parent aa8cb30920
commit 0ee7546cd2

View file

@ -18,13 +18,13 @@ def get_report_entries(lines: list) -> list:
def is_safe_single(reports: list) -> bool: def is_safe_single(reports: list) -> bool:
increasing = True increasing = True
decreasing = True decreasing = True
for i in range(len(reports) - 1): for a, b in zip(reports, reports[1:]):
distance = abs(reports[i] - reports[i + 1]) distance = abs(a - b)
if distance == 0 or distance > 3: if distance == 0 or distance > 3:
return False return False
if reports[i] > reports[i + 1]: if a > b:
increasing = False increasing = False
if reports[i] < reports[i + 1]: if a < b:
decreasing = False decreasing = False
return increasing or decreasing return increasing or decreasing