当前第2页 返回上一页
5、分别从两个列表中取出所有的元素,再放入新列表中
1 2 3 4 5 6 7 8 | list1 = [1,2,3]
list2 = [4,5,6]
list_new = []
for item in list1:
list_new.append(item)
for item in list2:
list_new.append(item)
print list_new
|
6、zip(),将几个本来无关的内容打包到一起
1 2 3 4 | a = [1,2,3]
b = [4,5,6]
c = zip(a,b)
list_new = [row[i] for i in range(len(0)) for row in c]
|
先打包,再降维,就这么简单。(其实一点也不简单,看到后面你就会有想打人的冲动)
以上就是Python怎么合并两个列表的详细内容,更多文章请关注木庄网络博客!!
返回前面的内容
相关阅读 >>
Python是什么?速读本文让你快速Python入门
Python基础教程项目三之万能的xml
Python如何实现颜色
Python怎么将整数反转输出
Python中线程与进程的区别与优劣
如何查看Python源代码
会java再去学Python容易吗
Python中迭代器和列表解析怎么使用?
如何学好Python
Python2与Python3中round四舍五入的区别介绍
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » Python怎么合并两个列表