+ 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 >>>
2 odpowiedzi
+ 6
`extend` method modifies the calling `list` object directly, it returns None. That's why you got the error.
+ 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::]]]