From bbb88bb5c261085ff23bce2b3c17266ebfa7b087 Mon Sep 17 00:00:00 2001 From: eee555 <50390200+eee555@users.noreply.github.com> Date: Fri, 13 May 2022 04:28:51 +0800 Subject: [PATCH] Fix bug in bucket_sort.py (#6005) --- sorts/bucket_sort.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sorts/bucket_sort.py b/sorts/bucket_sort.py index 58242a1cb..7bcbe61a4 100644 --- a/sorts/bucket_sort.py +++ b/sorts/bucket_sort.py @@ -54,8 +54,8 @@ def bucket_sort(my_list: list) -> list: bucket_count = int(max_value - min_value) + 1 buckets: list[list] = [[] for _ in range(bucket_count)] - for i in range(len(my_list)): - buckets[(int(my_list[i] - min_value) // bucket_count)].append(my_list[i]) + for i in my_list: + buckets[int(i - min_value)].append(i) return [v for bucket in buckets for v in sorted(bucket)]