Python中如何合并两个列表【面试题详解】

今天爱分享给大家带来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,转载请注明出处。
0
伊势之欲1.0.9.1.2汉化版[PC+安卓/1.00G/更新]Isekai Lust [v1.0.9.1.2] [日系SLG/汉化/沙盒]
伊势之欲1.0.9.1.2汉化版[PC+安卓/1.00G/更新]Isekai Lust [v1.0.9.1.2] [日系SLG/汉化/沙盒]
10分钟前 有人购买 去瞅瞅看

站点公告

显示验证码
没有账号?注册  忘记密码?