From 0e9f6959f24c2110d56a6ce249387776d83b80f9 Mon Sep 17 00:00:00 2001 From: Lucas Ma <7184042+pony-maggie@users.noreply.github.com> Date: Mon, 15 Jun 2026 07:58:28 +0800 Subject: [PATCH] fix: handle empty input in tim_sort --- sorts/tim_sort.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sorts/tim_sort.py b/sorts/tim_sort.py index 2eeed88b7399..c6da6c4fafa9 100644 --- a/sorts/tim_sort.py +++ b/sorts/tim_sort.py @@ -52,8 +52,12 @@ def tim_sort(lst: list[Any] | tuple[Any, ...] | str) -> list[Any]: True >>> tim_sort([3, 2, 1]) == sorted([3, 2, 1]) True + >>> tim_sort([]) + [] """ length = len(lst) + if length == 0: + return [] runs, sorted_runs = [], [] new_run = [lst[0]] sorted_array: list[Any] = []