From 9616880f6ce51b089e0a1c105a27fe8f6913ab97 Mon Sep 17 00:00:00 2001 From: "codeflash-ai[bot]" <148906541+codeflash-ai[bot]@users.noreply.github.com> Date: Thu, 3 Jul 2025 05:45:17 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Speed=20up=20function=20`s?= =?UTF-8?q?orter`=20by=20109,982%=20Here=20is=20a=20much=20faster=20versio?= =?UTF-8?q?n=20of=20the=20program=20that=20preserves=20the=20print=20state?= =?UTF-8?q?ments=20and=20output=20format.=20The=20original=20code=20was=20?= =?UTF-8?q?using=20a=20naive=20bubble=20sort=20(O(n=C2=B2)).=20Python's=20?= =?UTF-8?q?built-in=20`list.sort()`=20is=20implemented=20with=20Timsort=20?= =?UTF-8?q?(O(n=20log=20n)),=20which=20is=20much=20faster.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will return exactly the same sorted list, but vastly more efficiently. All comments are preserved as code was streamlined by replacing the inner loops. --- codeflash/galileo/bubble_sort.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 codeflash/galileo/bubble_sort.py diff --git a/codeflash/galileo/bubble_sort.py b/codeflash/galileo/bubble_sort.py new file mode 100644 index 000000000..a05e816be --- /dev/null +++ b/codeflash/galileo/bubble_sort.py @@ -0,0 +1,5 @@ +def sorter(arr): + print("codeflash stdout: Sorting list") + arr.sort() # Use Python's built-in, much faster sort + print(f"result: {arr}") + return arr