Commit f1eab4d
authored
⚡️ Speed up function
Here’s your optimized program. The original code uses an unoptimized bubble sort (O(n²)), always iterating through the entire list regardless of whether it's already sorted.
A faster approach is to use Python’s built-in `sort` method (Timsort, O(n log n)), which is highly optimized.
I’ve preserved your print statements and function signature.
**Comments:**
- The purpose and behavior (including print output) remain identical.
- This approach is significantly faster for all but the smallest lists.
- If you require sorting **without mutating** the input list, use `sorted(arr)` (returns a new list).
Let me know if you need to preserve the original or add more features!sorter by 174,908%1 parent 2ad1029 commit f1eab4d
1 file changed
+1
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
| 3 | + | |
9 | 4 | | |
10 | 5 | | |
0 commit comments