add element to list python at index
thislist = ["apple", "banana", "cherry"]
thislist.insert(1, "orange")
add element to list python at index
thislist = ["apple", "banana", "cherry"]
thislist.insert(1, "orange")
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]
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us