Skip to content

Commit 0cbc24d

Browse files
committed
Raise ValueError for negative inputs in radix_sort
1 parent 25bcced commit 0cbc24d

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

sorts/radix_sort.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ def radix_sort(list_of_ints: list[int]) -> list[int]:
2121
True
2222
>>> radix_sort([1,100,10,1000]) == sorted([1,100,10,1000])
2323
True
24+
>>> radix_sort([1, 3, -2, 4])
25+
Traceback (most recent call last):
26+
...
27+
ValueError: negative integers are not supported
2428
"""
29+
if any(i < 0 for i in list_of_ints):
30+
raise ValueError("negative integers are not supported")
31+
2532
placement = 1
2633
max_digit = max(list_of_ints)
2734
while placement <= max_digit:

0 commit comments

Comments
 (0)