For example, how do i do this:
x=[1,2,3]
y=[4,5,6]
list3=[1,4,5,6,2,3]
i do not want [1,[4,5,6],2,3]
basically i want to extend it, but at a given index
For example, how do i do this:
x=[1,2,3]
y=[4,5,6]
list3=[1,4,5,6,2,3]
i do not want [1,[4,5,6],2,3]
basically i want to extend it, but at a given index
Select an empty slice at the index you want, and insert the other list there:
>>> x=[1,2,3]
>>> y=[4,5,6]
>>> x[1:1]=y
>>> x
[1, 4, 5, 6, 2, 3]
Use slice assignment.
list3 = x[:] # make copy of x
list3[1:1] = y # replace empty slice at index 1