replace index-based for loop with iteration through zip
This commit is contained in:
parent
aa8cb30920
commit
0ee7546cd2
1 changed files with 4 additions and 4 deletions
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue