Here is a list in Python,
list = ["Red", "Blue", "Green", "White","Yellow"]
I want to Insert "Gray" into the second index of list. How to do this in Python?
python insert into list
To insert the specific value in a list, refer to the index of that particular value.
In your case, You have to insert Gray into the second index of the list, which means you have to insert it after "Blue". In the above example, "Red" stands to the 0th index and "Blue" stands to the 1st index. To insert it after the first index,
code will be like this,
list = ["Red", "Blue", "Green", "White","Yellow"]
list.insert(2, "gray")
print(list)
Output:
['Red', 'Blue', 'gray', 'Green', 'White', 'Yellow']