Question: make_list_of_lists(3) should return [ [], [1], [1, 2] ]. However, both attempts are incorrect. Locate the error in each function and explain why it goes
make_list_of_lists(3) should return [ [], [1], [1, 2] ]. However, both attempts are incorrect. Locate the error in each function and explain why it goes wrong.
Function 1
def make_list_of_lists(n): the_list = [] sublist = [] while n > 0: the_list.append(sublist) sublist.append(len(sublist) + 1) n = n - 1 return the_list
Function 2
def make_list_of_lists(n): the_list = [] sublist = [] for i in range(n): the_list.extend(sublist) sublist = sublist.insert(len(sublist), i) return the_list
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
