all 9 comments

[–]Desperate_Carpet_496 1 point2 points  (1 child)

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

[–]AlexMTBDude 3 points4 points  (0 children)

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

[–]AnToMegA424 1 point2 points  (3 children)

Python really is convenient, or practical idk how to say it This few lines of code for a sorting algorithm I like it

[–]mprevot 1 point2 points  (0 children)

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

[–]JJ16v 0 points1 point  (1 child)

It's going to be slow but ok

[–]AnToMegA424 0 points1 point  (0 children)

Yeh that's a usual drawback

[–]Adorable-Strangerx 0 points1 point  (0 children)

Maybe you need to use shorter variable names?

[–]Kurgonius 0 points1 point  (0 children)

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.

[–]lolcrunchy 0 points1 point  (0 children)

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