2015년 2월 7일 토요일

CSC148 Week5 Slog

      Throughout the week 4 in the lecture, we learned about recursion in the class. From what I learned, recursion is a function in a function. It means that for example, if the function is called count_list(L), then inside that function there is also function called count_list but the variable inside is different like x. To write that we have to write 'for x in L' then write count_list(x). For the recursion, else part is important because when the function inside the function reaches the end, it goes to else part and get value from the else part.

      Tracing the recursion function was easy after I knew how to do it. It was just following what the function said. For most of the recursion, there are isinstance(L, list) and else part. If the L part to put in the function was a list, then I go to isinstance part and follow it then at the end, there is a recursion function. It is like go inside the L and if the x in L is list then go to isinstance part again. If not, then go to else then change value inside to what else says. Then if it says sum, sum them up. It was hard for me at first, but after I practiced it at home, I understood how the recursion worked. 

댓글 없음:

댓글 쓰기