From f77c2ffc8e66231ad6b0893595e4256ec2e8fda5 Mon Sep 17 00:00:00 2001 From: Thayer Marvin Date: Sat, 25 Jul 2026 02:07:00 +0000 Subject: [PATCH] Added validation to confirm the number of buckets is an integer. --- sorts/bucket_sort.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sorts/bucket_sort.py b/sorts/bucket_sort.py index 893c7ff3a23a..f560b4aaf130 100644 --- a/sorts/bucket_sort.py +++ b/sorts/bucket_sort.py @@ -71,11 +71,19 @@ def bucket_sort(my_list: list, bucket_count: int = 10) -> list: >>> data = [9, 2, 7, 1, 5] >>> bucket_sort(data) == sorted(data) True + >>> data = [12, 7 , 22, 11, 4] + >>> bucket_sort(data, 2.5) + Traceback (most recent call last): + ... + TypeError: bucket_count must be an integer """ if len(my_list) == 0 or bucket_count <= 0: return [] + if not isinstance(bucket_count, int): + raise TypeError("bucket_count must be an integer") + min_value, max_value = min(my_list), max(my_list) if min_value == max_value: return my_list