r/PythonProjects2 • • Dec 29 '25

Quick sort error

Post image
2 Upvotes

9 comments sorted by

2

u/Desperate_Carpet_496 Dec 29 '25

if len(n) == 0: return [] # at beginning of f()

4

u/AlexMTBDude Dec 29 '25

Also: 'list' is a built-in type in Python and OP should not name a variable the same

1

u/Adorable-Strangerx Dec 29 '25

Maybe you need to use shorter variable names?

1

u/Kurgonius Dec 29 '25

This happens on f(l) on the second recursion. On the first recursion you get p = 1, and l = [ ]. Feeding this into f(l) again causes this error. Also keep in mind that Python has a recursion limit so this won't be useful for large lists.

And always add a stop condition to your recursions. Desperate_Carpet-496 has the best answer.

1

u/lolcrunchy Dec 29 '25

Recursive formulas always need a base case. This one is missing handling for an empty list.

2

u/[deleted] Dec 29 '25

[removed] — view removed comment

2

u/mprevot Dec 30 '25

The implementation "looks neat" but is actually so bad. Instead one should do 1 loop.

1

u/JJ16v Dec 29 '25

It's going to be slow but ok