Answers for "insert element in the middle of a list python"

12

add element to list python at index

thislist = ["apple", "banana", "cherry"]
thislist.insert(1, "orange")
Posted by: Guest on May-17-2020
0

add to middle of list python

# To insert an item at the 4th index of a list:

myList = [1, 2, 3, 4, 5]
insertThis = 5

# First argument is the index, second is what you wish to add.
myList.insert(3, insertThis)

print(myList)
# >>> [1, 2, 3, 5, 4, 5]
Posted by: Guest on June-06-2021

Code answers related to "insert element in the middle of a list python"

Python Answers by Framework

Browse Popular Code Answers by Language