Use the insort function of the bisect module:

import bisect 
a = [1, 2, 4, 5] 
bisect.insort(a, 3) 
print(a)

Output

[1, 2, 3, 4, 5] 

For more complicated usage, check key parameter for insort method

import bisect
a = [{"key": 1}, {"key": 3}]
bisect.insort(a, {"key": 2}, key=lambda x: x["key"])
print(a)

Output

[{"key": 1}, {"key": 2}, {"key": 3}]
Answer from stanga on Stack Overflow
🌐
W3Schools
w3schools.com › python › ref_list_insert.asp
Python List insert() Method
Python Examples Python Compiler ... Python Bootcamp Python Certificate Python Training ... The insert() method inserts the specified value at the specified position....
🌐
Programiz
programiz.com › python-programming › methods › list › insert
Python List insert()
Become a certified Python programmer. Try Programiz PRO! ... The insert() method inserts an element to the list at the specified index.
Discussions

Insert an item into sorted list in Python - Stack Overflow
Thus, as commented by nz_21, manually iterating through the sorted list, looking for the right position, would be just as good in terms of complexity. In fact, simply sorting the array after inserting a new value will probably be fine, too, since Python's Timsort has a worst-case complexity ... More on stackoverflow.com
🌐 stackoverflow.com
python - In place insertion into list (or array) - Stack Overflow
I'm running a script in Python, where I need to insert new numbers into an array (or list) at certain index locations. The problem is that obviously as I insert new numbers, the index locations are More on stackoverflow.com
🌐 stackoverflow.com
Lists in Python: .append() v. .insert()
What you just said - append appends elements to the end, insert inserts them in an arbitrary position. More on reddit.com
🌐 r/learnpython
4
1
August 11, 2020
What is the Time complexity (Big O) for insertion of an element in the end of an Array?
Python’s array.array is not a contiguous block of memory at all, and bears little direct resemblance to a C array. Like list the underlying data structure is a dynamic array , and gains all of its performance characteristics (and compromises) from it. In a running Python process the only distinct advantage of array.array is that it’s got a fixed content type, which makes it a little easier to reason about and also makes resizing operations slightly more efficient (though not Big-O influencing more efficient). Where it really shines is when you need to be able to transmit or receive data as a C-style packed continuous array of bytes, which is why it has numerous methods for writing and reading to such a representation. If you know C you can find it’s CPython implementation here , it’s actually pretty simple and well commented. More on reddit.com
🌐 r/learnpython
9
1
January 3, 2021
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-list-insert
Python List insert() Method With Examples - GeeksforGeeks
August 12, 2024 - Python List insert() method inserts an item at a specific index in a list.
🌐
Python documentation
docs.python.org › 3 › tutorial › datastructures.html
5. Data Structures — Python 3.14.3 documentation
It is also possible to use a list as a queue, where the first element added is the first element retrieved (“first-in, first-out”); however, lists are not efficient for this purpose. While appends and pops from the end of list are fast, doing inserts or pops from the beginning of a list is slow (because all of the other elements have to be shifted by one).
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python list insert() with examples
Python List insert() with Examples - Spark By {Examples}
May 31, 2024 - Python list.insert() method is used to insert an element to the list at a particular position, by using this you can insert an element or iterable at the
Find elsewhere
🌐
NumPy
numpy.org › doc › 2.3 › reference › generated › numpy.insert.html
numpy.insert — NumPy v2.3 Manual
>>> import numpy as np >>> a = np.arange(6).reshape(3, 2) >>> a array([[0, 1], [2, 3], [4, 5]]) >>> np.insert(a, 1, 6) array([0, 6, 1, 2, 3, 4, 5]) >>> np.insert(a, 1, 6, axis=1) array([[0, 6, 1], [2, 6, 3], [4, 6, 5]])
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-add-to-array
Python Array Add: How to Append, Extend & Insert Elements | DigitalOcean
April 15, 2025 - Learn how to add elements to an array in Python using append(), extend(), insert(), and NumPy functions. Compare performance and avoid common errors.
🌐
DataCamp
datacamp.com › doc › numpy › insert-numpy
NumPy insert()
NumPy's insert() function allows you to insert values into an array at specified indices, creating a new array with the inserted values.
🌐
PhoenixNAP
phoenixnap.com › home › kb › devops and development › add elements to python array
Add Elements to Python Array (3 Methods)
December 15, 2025 - The new element inserts at the provided index, while all the following values shift to the right by one index. The Python array module mimics traditional arrays, where all elements are restricted to the same data type. The module is similar to lists when it comes to adding new elements.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.insert.html
numpy.insert — NumPy v2.1 Manual
>>> import numpy as np >>> a = np.arange(6).reshape(3, 2) >>> a array([[0, 1], [2, 3], [4, 5]]) >>> np.insert(a, 1, 6) array([0, 6, 1, 2, 3, 4, 5]) >>> np.insert(a, 1, 6, axis=1) array([[0, 6, 1], [2, 6, 3], [4, 6, 5]])
Top answer
1 of 5
8

Insert those values in backwards order. Like so:

original_list = [0, 1, 2, 3, 4, 5, 6, 7]
insertion_indices = [1, 4, 5]
new_numbers = [8, 9, 10]

new = zip(insertion_indices, new_numbers)
new.sort(reverse=True)

for i, x in new:
    original_list.insert(i, x)

The reason this works is based on the following observation:

Inserting a value at the beginning of the list offsets the indexes of all other values by 1. Inserting a value at the end though, and the indexes remain unchanged. As a consequence, if you start by inserting the value with the largest index (10) and continue "backwards" you would not have to update any indexes.

2 of 5
7

Being NumPy tagged and since input is mentioned as list/array, you can simply use builtin numpy.insert -

np.insert(original_list, insertion_indices, new_numbers)

To roll out the theory as a custom made one (mostly for performance), we could use mask, like so -

def insert_numbers(original_list,insertion_indices, new_numbers):
    # Length of output array                               
    n = len(original_list)+len(insertion_indices)

    # Setup mask array to selecrt between new and old numbers
    mask = np.ones(n,dtype=bool)
    mask[insertion_indices+np.arange(len(insertion_indices))] = 0

    # Setup output array for assigning values from old and new lists/arrays
    # by using mask and inverted mask version
    out = np.empty(n,dtype=int)
    out[mask] = original_list
    out[~mask] = new_numbers
    return out

For list output, append .tolist().

Sample run -

In [83]: original_list = [0, 1, 2, 3, 4, 5, 6, 7]
    ...: insertion_indices = [1, 4, 5]
    ...: new_numbers = [8, 9, 10]
    ...: 

In [85]: np.insert(original_list, insertion_indices, new_numbers)
Out[85]: array([ 0,  8,  1,  2,  3,  9,  4, 10,  5,  6,  7])

In [86]: np.insert(original_list, insertion_indices, new_numbers).tolist()
Out[86]: [0, 8, 1, 2, 3, 9, 4, 10, 5, 6, 7]

Runtime test on a 10000x scaled dataset -

In [184]: original_list = range(70000)
     ...: insertion_indices = np.sort(np.random.choice(len(original_list), 30000, replace=0)).tolist()
     ...: new_numbers = np.random.randint(0,10, len(insertion_indices)).tolist()
     ...: out1 = np.insert(original_list, insertion_indices, new_numbers)
     ...: out2 = insert_numbers(original_list, insertion_indices, new_numbers)
     ...: print np.allclose(out1, out2)
True

In [185]: %timeit np.insert(original_list, insertion_indices, new_numbers)
100 loops, best of 3: 5.37 ms per loop

In [186]: %timeit insert_numbers(original_list, insertion_indices, new_numbers)
100 loops, best of 3: 4.8 ms per loop

Let's test out with arrays as inputs -

In [190]: original_list = np.arange(70000)
     ...: insertion_indices = np.sort(np.random.choice(len(original_list), 30000, replace=0))
     ...: new_numbers = np.random.randint(0,10, len(insertion_indices))
     ...: out1 = np.insert(original_list, insertion_indices, new_numbers)
     ...: out2 = insert_numbers(original_list, insertion_indices, new_numbers)
     ...: print np.allclose(out1, out2)
True

In [191]: %timeit np.insert(original_list, insertion_indices, new_numbers)
1000 loops, best of 3: 1.48 ms per loop

In [192]: %timeit insert_numbers(original_list, insertion_indices, new_numbers)
1000 loops, best of 3: 1.07 ms per loop

The performance just shoots up, because there's no runtime overhead on conversion to list.

🌐
Reddit
reddit.com › r/learnpython › lists in python: .append() v. .insert()
r/learnpython on Reddit: Lists in Python: .append() v. .insert()
August 11, 2020 -

Hello. I was learning lists and its formats and stuff like that. I soon came across .append() method and .insert() method. So far with my tests, they but work quite similarly to each other. However, I soon found out that you can not add any elements in the middle of a list using the .append(), but you can insert any new elements in the middle of the list using .insert().

Thus, what is the difference between .append() method and .insert() method?

Thank you.

🌐
Cherry Servers
cherryservers.com › home › blog › cloud computing › how to add elements to a list in python? | 4 methods
How to Add Elements to a List in Python? | Cherry Servers
November 7, 2025 - The insert() method takes two parameters: the index of the new element to be added and the value of the element.
🌐
Index.dev
index.dev › blog › prepend-an-element-to-a-short-python-list
Prepend Elements to Python Lists: A Quick Guide
August 26, 2024 - Learn how to efficiently prepend an element to a short Python list using simple and effective methods like list slicing and the insert() method. Perfect for quick operations in small lists!
🌐
Mimo
mimo.org › glossary › python › insert()
Python List insert(): Master List Manipulation
Learn Python's list insert() method to add elements anywhere in a list. Explore examples for dynamic data manipulation, task prioritization, and more.
🌐
W3Schools
w3schools.com › python › python_arrays.asp
Python Arrays
Python DSA Lists and Arrays Stacks Queues Linked Lists Hash Tables Trees Binary Trees Binary Search Trees AVL Trees Graphs Linear Search Binary Search Bubble Sort Selection Sort Insertion Sort Quick Sort Counting Sort Radix Sort Merge Sort
🌐
Nanyang Technological University
libguides.ntu.edu.sg › python › insertelementsintoarrays
NP.9 Inserting elements into arrays - Python for Basic Data Analysis - LibGuides at Nanyang Technological University
Let's add 11,12 and 13 between the 2nd and 3rd elements. First, we first add square brackets around the numbers to be added. Next, we specify the index 2, to insert these numbers before the third element. To work with 2-D arrays, we cannot simply add a random number of elements.
🌐
Reddit
reddit.com › r/learnpython › what is the time complexity (big o) for insertion of an element in the end of an array?
r/learnpython on Reddit: What is the Time complexity (Big O) for insertion of an element in the end of an Array?
January 3, 2021 -

Assume I have a code:

arr1=array("i", [1, 2, 3, 4, 5])

I just wanted to ask what would be the time complexity for inserting an element at the end of the array by using the code:

arr1.insert(5,6)

output: array('i', [1, 2, 3, 4, 5, 6])

Although, I found online that Big O is O(1) but I don't get it. Initially my array was of fixed sized(5) and if I need to add a new element, I am essentially copying the old array [1,2,3,4,5] and pasting it in a new memory location with an empty space at the end so that I could add [6] in the end. This is my understanding, if this is right how is O(1) correct? shouldn't it be more?

Edit: It's O(n)

🌐
Medium
medium.com › @shrutimandaokar2301 › inserting-an-element-into-an-array-in-python-step-by-step-guide-68e673c3dba1
Inserting an Element into an Array in Python: Step-by-Step Guide | by Shruti Mandaokar | Medium
April 3, 2025 - Placing the New Element: We insert 7 at index 2. Updating Size: The size variable is increased to reflect the new length. Printing the Array: The final loop prints the updated array. ... The shifting operation runs in O(n) time complexity because we may need to move all elements in the worst case. The space complexity is O(1) as we modify the array in place. Alternative Approach Using Python’s insert() Method While the above approach demonstrates manual shifting, Python provides a built-in method to insert an element efficiently: