Insert an element at a specific index in a list and return the updated list

l.insert(index, obj) doesn’t actually return anything. It just updates the list.

As ATO said, you can do b = a[:index] + [obj] + a[index:].
However, another way is:

a = [1, 2, 4]
b = a[:]
b.insert(2, 3)

Leave a Comment