K12教育赛事综合服务平台
聚乐之家官方网站
下载聚乐之家官方App
专注青少年竞赛题库网站
已知嵌套列表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]