看这一行:
sublist = sublist.insert(len(sublist), i+1)
insert
None
,所以在下面的迭代中
the_list.extend(sublist)
sublist
是
虽然
extend
函数需要iterable参数。固定代码:
def make_list_of_lists(n):
the_list = []
sublist = []
for i in range(n):
print(sublist)
the_list.extend(sublist)
sublist.insert(len(sublist), i + 1)
return the_list
make_list_of_lists(3)
[一]
[1,2]