0

I have a list A=[[1,2],[2,3],[4,5]] and i want to insert [2,2] at index=1 in list A. What should i do? I am not suppose to use any package for this. The final array will be: A=[[1,2],[2,2],[2,3],[4,5]] The following code I used but it is giving error:

A.insert([2,2],1)

1 Answer 1

2

you can use:

A.insert(1, [2, 2])

from the docs:

list.insert(i, x)

Insert an item at a given position. The first argument is the index of the element before which to insert, so a.insert(0, x) inserts at the front of the list, and a.insert(len(a), x) is equivalent to a.append(x).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.