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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!