想把一个 list
插入到另一个 list
的倒数第二位并展开。有什么简单的办法不
a = [1,2,3,4]
b = ["a", "b"]
c = [1,2,3,"a","b",4] #如何让 c 等于这样?
1
zhusimaji 2019-08-06 16:40:19 +08:00 via Android
a[:-1]+b+a[-1]
|
2
cassidyhere 2019-08-06 17:33:32 +08:00
a[-2:-1] = b
|
3
Abirdcfly 2019-08-07 04:32:59 +08:00
c = a[:-1] + b + a[-1]
或者 a[-1:0]=b |
4
xpresslink 2019-08-07 09:53:17 +08:00
二楼+100086
|
5
sladesha 2019-08-07 16:24:49 +08:00
a[-1:-1] = b 即可
|
6
hongda0812 2019-08-07 16:29:14 +08:00
也可取出 list 遍历也行
|