During the past few weeks, we have been focusing on the concept of recursion. Recursion is a powerful and useful tool as it helps reduce and simplify coding in Python or be used to model and simply real world problems. In terms of python programming, recursion is basically when a function or method calls upon itself in its body code. For myself, the concept of recursion was not too difficult to grasp as it is for writing recursion code itself. Generally, it is somewhat easy to distinguish when to use or when it is appropriate to use recursion. If the problem at hand has a general pattern (i.e. Having to do a process or action multiple times in the same manner) then that is a good indication that recursion would be useful.
In terms of writing actual recursive functions and methods, this part is a bit tougher. However, there are many ways to simply the process and make writing recursive structures easier. Emphasizing again recursion is where the function or method calls itself x number of timed depending on what is passed into the parameters. This means that there will be x number of "steps" or results. One might think, "how do you know if each step/call is producing the correct value/answer?or wouldn't it be hard to track all the values/variables that each step/call produces?". In order to wrote code to makes sure produced answers are correct is to start off with the simplest case. The simplest case is usually when the function or method should stop calling the recursive structure (i.e. The function has no need to call the recursive structure and just return a simple value/None, requiring no recursion. This simple can be referred to the base case and it required for a recursive function to work. If a base case is not defined then one problem would be that the function would endlessly continue to call itself, or as Python would like to put it, "maximum recursion depth exceeded!". The base case is also a good steeping stone to begin writing difficult recursive functions.
Since the base case is the simple case where if recursion is not needed ( the function doesn't need to call itself again) then the base case is executed. When starting off with the simple and continue with recurs ion and calling the function x numbers of times, we automatically know intermediate answers/values (i.e. In a nested list, we are able to identify the answers of the nested items without having to trace through them). Therefore recursive enforces a "lazy" approach.