今天爱分享给大家带来Python中如何合并两个列表【面试题详解】,希望能够帮助到大家。
listone = [1,2,3] listtwo = [4,5,6] #outcome we expect: mergedlist == [1, 2, 3, 4, 5, 6]
1.不考虑顺序(原来问题不是很明确)
listone + listtwo #linstone.extend(listtwo)也行,就是会修改listone
2.考虑顺序做些处理
>>> listone = [1,2,3] >>> listtwo = [4,5,6] >>> import itertools >>> for item in itertools.chain(listone, listtwo): ... print item ... 1 2 3 4 5 6
常见问题
不显示资源下载框怎么办?
请更换谷歌,微软,火狐等浏览器
微云登录不了,或者重复提示登录?
请更换浏览器,最好使用微软,谷歌,火狐。国产浏览器不好用
原文链接:https://blog.itblood.com/4434.html,转载请注明出处。
