why is it return x and not return double_list(x) or smthng
Because then it would be recursive; an infinite loop if no base case exists. It would run out of stack space in a matter of milliseconds.
The function is an abstract operation on a list,
x, whereupon it returns
x once said operation is complete. Hence,
>>> def double_list(x): return [i * 2 for i in x] >>> double_list(range(1, 10)) [2, 4, 6, 8, 10, 12, 14, 16, 18] >>>
Don’t worry. You will not be expected to understand this code for a few units yet. I only want to show that all we return is the amended list. No recursion needed or recommended. Ignore the code you see, for now. It will come up in the track.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.