I am working on some project, and it requires me to do something like this
[10, 15, 17, 18]
->
[10, 12, 15, 17, 18]
Like this, I need to put an element in between of two elements. I did try
mylist = [10, 15, 17, 18]
mylist.append(mylist[-1])
for i in range(2):
mylist[-1 * i - 2] = mylist[-1 * i - 3]
mylist[-4] = 12
But I don't think this is efficient, and the code will probably be messy if I put this in more sophisticated codes. Is there a function to automatically do this?