用列表推导式如何生成如下列表:[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
inner_list = [] outer_list = [] for i in range(1,10): inner_list.append(i) if i % 3 == 0: outer_list.append(inner_list) inner_list = [] print(outer_list)
运行
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
用列表推导式如何生成如下列表:[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
inner_list = [] outer_list = [] for i in range(1,10): inner_list.append(i) if i % 3 == 0: outer_list.append(inner_list) inner_list = [] print(outer_list)
运行
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]