Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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]
 
PREVIOUS NEXT
Tagged: #add #middle #list #python
ADD COMMENT
Topic
Name
8+2 =