Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion sorts/bucket_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
from __future__ import annotations


def bucket_sort(my_list: list, bucket_count: int = 10) -> list:
def bucket_sort(
my_list: list[int | float], bucket_count: int = 10
) -> list[int | float]:
"""
>>> data = [-1, 2, -5, 0]
>>> bucket_sort(data) == sorted(data)
Expand Down Expand Up @@ -65,6 +67,10 @@ def bucket_sort(my_list: list, bucket_count: int = 10) -> list:
True
>>> bucket_sort([1]) == [1]
True
>>> bucket_sort([1, 2, 3], 2.5)
Traceback (most recent call last):
...
TypeError: bucket_count must be an integer
>>> data = [-1.1, -1.5, -3.4, 2.5, 3.6, -3.3]
>>> bucket_sort(data) == sorted(data)
True
Expand All @@ -73,6 +79,8 @@ def bucket_sort(my_list: list, bucket_count: int = 10) -> list:
True
"""

if not isinstance(bucket_count, int):
raise TypeError("bucket_count must be an integer")
if len(my_list) == 0 or bucket_count <= 0:
return []

Expand Down
Loading