From fcb5a5b6177bc1b020ece7f577b195d49527647c Mon Sep 17 00:00:00 2001 From: ashay tiwari Date: Sat, 22 Aug 2026 12:55:58 +0530 Subject: [PATCH 1/2] fix: validate bucket_count type in bucket_sort --- sorts/bucket_sort.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/sorts/bucket_sort.py b/sorts/bucket_sort.py index 893c7ff3a23a..3704b563f8f5 100644 --- a/sorts/bucket_sort.py +++ b/sorts/bucket_sort.py @@ -71,22 +71,23 @@ def bucket_sort(my_list: list, bucket_count: int = 10) -> list: >>> data = [9, 2, 7, 1, 5] >>> bucket_sort(data) == sorted(data) True + >>> bucket_sort([1, 4, 3, 2, 6], 1.5) + Traceback (most recent call last): + ... + TypeError: bucket_count must be an integer """ - + if not isinstance(bucket_count, int): + raise TypeError("bucket_count must be an integer") if len(my_list) == 0 or bucket_count <= 0: return [] - min_value, max_value = min(my_list), max(my_list) if min_value == max_value: return my_list - bucket_size = (max_value - min_value) / bucket_count buckets: list[list] = [[] for _ in range(bucket_count)] - for val in my_list: - index = min(int((val - min_value) / bucket_size), bucket_count - 1) - buckets[index].append(val) - + index = min(int((val - min_value) / bucket_size), bucket_count - 1) + buckets[index].append(val) return [val for bucket in buckets for val in sorted(bucket)] From 3a5ca66d89e6d99ebb9cf1d9be0aa949f73d1e14 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 22 Aug 2026 07:29:44 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- 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 3704b563f8f5..31c6cfc8a089 100644 --- a/sorts/bucket_sort.py +++ b/sorts/bucket_sort.py @@ -86,8 +86,8 @@ def bucket_sort(my_list: list, bucket_count: int = 10) -> list: bucket_size = (max_value - min_value) / bucket_count buckets: list[list] = [[] for _ in range(bucket_count)] for val in my_list: - index = min(int((val - min_value) / bucket_size), bucket_count - 1) - buckets[index].append(val) + index = min(int((val - min_value) / bucket_size), bucket_count - 1) + buckets[index].append(val) return [val for bucket in buckets for val in sorted(bucket)]