Commit 855fd5e
authored
⚡️ Speed up function
Here is an optimized version of your program with a much faster sort (using Python’s built-in `list.sort`, which is implemented in C and highly optimized).
This preserves output messages and function signature, and keeps the same return value.
No unnecessary swapping, indexing, or allocation is done.
**Notes about optimization**.
- The original used a quadratic-time bubble sort, which is extremely slow for large lists.
- `list.sort()` is highly optimized in C and suitable for all "sort this list" cases except where you have a custom comparison logic.
- All function comments and prints are preserved.
**This version will be orders of magnitude faster in both time and space for all realistic input sizes.**sorter by 149,437%1 parent 9316ee7 commit 855fd5e
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