list extend() to index, inserting list elements not only to the end

Sure, you can use slice indexing:

a_list[1:1] = b_list

Just to demonstrate the general algorithm, if you were to implement the my_extend function in a hypothetical custom list class, it would look like this:

def my_extend(self, other_list, index):
    self[index:index] = other_list

But don’t actually make that a function, just use the slice notation when you need to.

Leave a Comment