已知嵌套列表nested_list = [[10, 20], [30, 40], [50]],需要将其所有元素收集到一维列表flat_list中,下列代码实现正确的是?
nested_list = [[10, 20], [30, 40], [50]]
flat_list
flat_list = [] for item in nested_list: flat_list.append(item)
flat_list = [] for sub_list in nested_list: flat_list += sub_list
flat_list = [] nested_list.each(lambda x: flat_list.extend(x))
flat_list = [n for n in nested_list]