Skip to content

Commit 6563afd

Browse files
authored
fix: handle empty input in tim_sort (#14805)
Co-authored-by: Lucas Ma <7184042+pony-maggie@users.noreply.github.com>
1 parent 4c3ba66 commit 6563afd

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

sorts/tim_sort.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ def tim_sort(lst: list[Any] | tuple[Any, ...] | str) -> list[Any]:
5252
True
5353
>>> tim_sort([3, 2, 1]) == sorted([3, 2, 1])
5454
True
55+
>>> tim_sort([])
56+
[]
5557
"""
58+
if not lst:
59+
return []
5660
length = len(lst)
5761
runs, sorted_runs = [], []
5862
new_run = [lst[0]]

0 commit comments

Comments
 (0)