Commit c2feef6
authored
⚡️ Speed up function
Here’s a **faster** rewrite of your function, using Python's built-in `list.sort()` method, which is implemented in C and highly optimized (Timsort algorithm). The functionality (in terms of output and in-place sorting) and print statements are preserved.
---
### Why it's faster
- The old approach is a pure-Python bubble sort O(N²); `list.sort()` is O(N log N) for most inputs and runs in optimized C code.
- The result and printed output are unchanged, as required.
---
If, for some reason, you **must not** use built-in sort and need a manual fast implementation, a simple in-place quicksort or mergesort would still be much faster than bubble sort. **But `arr.sort()` is fastest and most idiomatic in Python.**sorter by 125,980%1 parent 8b2f948 commit c2feef6
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