diff --git a/sorts/bucket_sort.py b/sorts/bucket_sort.py index 98185cbd32ca..4dba0cc22d0d 100644 --- a/sorts/bucket_sort.py +++ b/sorts/bucket_sort.py @@ -65,6 +65,9 @@ def bucket_sort( >>> data = [5.5, 2.2, -1.1, 3.3, 0.0] >>> bucket_sort(data) == sorted(data) True + >>> bucket_sort(data, 2.5) + Traceback (most recent call last): + TypeError: bucket_count must be an integer >>> bucket_sort([1]) == [1] True >>> bucket_sort([1, 2, 3], 2.5) @@ -83,9 +86,9 @@ def bucket_sort( TypeError: bucket_count must be an integer """ - if not isinstance(bucket_count, int): + if not isinstance(bucket_count, (bool, int)): raise TypeError("bucket_count must be an integer") - if len(my_list) == 0 or bucket_count <= 0: + if not my_list or bucket_count <= 0: return [] min_value, max_value = min(my_list), max(my_list)