From 2c1816bf102eeec5aa39cb2f1806afb64b672d14 Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Tue, 9 Apr 2024 01:57:38 +0300 Subject: [PATCH] Update sorts/bead_sort.py Co-authored-by: Christian Clauss --- sorts/bead_sort.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sorts/bead_sort.py b/sorts/bead_sort.py index 6f33d129d..2e6fa5161 100644 --- a/sorts/bead_sort.py +++ b/sorts/bead_sort.py @@ -31,9 +31,9 @@ def bead_sort(sequence: list) -> list: if any(not isinstance(x, int) or x < 0 for x in sequence): raise TypeError("Sequence must be list of non-negative integers") for _ in range(len(sequence)): - for i in range(len(sequence) - 1): - if sequence[i] > sequence[i + 1]: - sequence[i], sequence[i + 1] = sequence[i + 1], sequence[i] + for i, (rod_upper, rod_lower) in enumerate(pairwise(sequence)): + if rod_upper > rod_lower: + sequence[i], sequence[i + 1] = rod_lower, rod_upper return sequence