WEEK 4 RECURSION
What we learned in week 4 is recursion on python, which is a typical method to trace every step ran in a function call with only known the body part. What's more importantly, recuision illustrates the function is used again and again in just one particular function call. The most basic thing in recursionis carefully finding out every step without docstring description. The sum_list described in the lecture can be a basic example for recursion.
The attributes in the sum_list is a list, however, it could be a nested list. Therefore, sum should be used when the elements in the list are all integers. Whenever the element is a list, sum_list should be used again. It won't stop tracing until the elements are all not list.
For example, we need to trace this call.
This screenshot clearly illustrates how this call being traced step by step.
No comments:
Post a Comment