串联子列表python [英] concatenating sublists python

查看:67
本文介绍了串联子列表python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似的清单: n = [[1、2、3],[4、5、6、7、8、9]]

I have one list like: n = [[1, 2, 3], [4, 5, 6, 7, 8, 9]]

我想创建一个函数,该函数采用一个列表(请参见上文),并将属于该列表的所有子列表连接到一个列表中.

I want to create a function that takes a single list (see above) and concatenates all the sublists that are part of it into a single list.

推荐答案

n = [[1, 2, 3], [4, 5, 6, 7, 8, 9]]
nn = [ x for y in n for x in y]

这篇关于串联子列表python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆