Update sorts/bead_sort.py

Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
Maxim Smolskiy 2024-04-09 01:57:38 +03:00 committed by GitHub
parent bc2225df45
commit 2c1816bf10
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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