+ 2

Is it possible to concatenate an extended list (using extend() method) to another list?

>>> a=[5,9,38,2,5,3,[5,6,93,8],56] >>> a [5, 9, 38, 2, 5, 3, [5, 6, 93, 8], 56] >>> a=a[0:6]+a.extend(a[6])+a[7:] Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: can only concatenate list (not "NoneType") to list >>>

6th Mar 2020, 2:16 PM
sai
2 ответов
+ 6
`extend` method modifies the calling `list` object directly, it returns None. That's why you got the error.
6th Mar 2020, 2:27 PM
Ipang
+ 5
a= a +a[6]+a[7::] will do it also a=[5,9,38,2,5,3,[5,6,93,8],56] [a.extend(l) for l in[a[6],a[7::]]]
6th Mar 2020, 2:36 PM
Oma Falk
Oma Falk - avatar