Say I have a nested list such as:
a = [[4,5,7],[3,5,7],[5,8,0]]
I want to insert the inner list z=[0,0,0] into specific locations within the list a. The locations are determined by a list call index.
So if the index list is:
index = [2,4,5]
The result would be z inserted into a at locations 2,4 and 5. The resultant list would be:
a_insert = [[[4,5,7],[3,5,7],[0,0,0],[5,8,0],[0,0,0],[0,0,0]]
2 4 5
^ ^ ^
Where the list [0,0,0] is now inserted at the locations specified by the list index.
A naive attempt is,
for ind in index:
c = a.insert(ind,z)
which does not work. Can anyone suggest a solution?
cwill always be bound toNone, sinceinsertmutates the list in-place and does not return anything.