Jan-14-2021, 09:20 PM
Note: Your functions are iterative, not recursive. @deanhystad is right there. A recursive function to find the smallest element in your list would, as @deanhystad pointed out, call itself, like this implementation of "find_the_smallest_element" (from my first solution):
def find_the_smallest_element(lst): def inner(lst, el): if not lst: return el elif lst[0] < el: return inner(lst[1:], lst[0]) else: return inner(lst[1:], el)Where the recursion takes place in the embedded function "inner", still the same simplicity: (a) how do we take a step to a solution and (b) how do we know when to stop (even if the stop condition mostly occurs as the first branch).