Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk2 min

How to Insert Multiple Elements into a List in Python

Use items[index:index] = values to insert an iterable’s contents at a chosen position in a Python list. Use extend() to add several values at the end.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To insert several values at a specific position in a Python list, assign them to an empty slice: items[index:index] = values. For example, items[1:1] = ["b", "c"] inserts both values before the item currently at index 1. To add values at the end, use items.extend(values).

Insert multiple values at a specific index

Use a slice whose start and end are the same. This selects no existing elements, so Python inserts the iterable’s contents at that position without replacing anything:

items = ["a", "d"]
items[1:1] = ["b", "c"]
print(items)  # ['a', 'b', 'c', 'd']

The slice starts at index 1, so the new values go before the element that was at that index. Slice assignment accepts an iterable, not just a list; for example, a generator works too:

items = [10, 40]
new_values = (value for value in (20, 30))
items[1:1] = new_values
# items is now [10, 20, 30, 40]

Use the ordinary contiguous slice form items[index:index] for insertion. Extended slices with a step other than 1 have a length constraint: the assigned iterable must contain as many items as the slice selects. See the Python built-in types reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the operation that matches the job

Need Use What it does
Insert several values at a chosen position items[index:index] = values Inserts the iterable’s contents at the index without removing existing elements.
Add several values at the end items.extend(values) Appends the iterable’s contents to the list.
Insert one value before an index items.insert(index, value) Inserts a single value. At len(items), it is equivalent to appending one value.

Python documents insert and extend in its list-method tutorial; slice assignment is defined in the built-in types reference.

Why list.insert() adds only one value

list.insert(index, value) takes one value and places it before the element at index. If you pass a list as the value, that list becomes one nested element; its contents are not spread into the original list. For a batch of values, use empty-slice assignment at a chosen position or extend at the end.

You can call insert repeatedly, but repeated calls at one fixed index reverse the input order unless you process the values in reverse:

items = ["a", "d"]
for value in reversed(["b", "c"]):
    items.insert(1, value)
# ['a', 'b', 'c', 'd']

Each call inserts before whatever is currently at index 1. A direct batch slice assignment is usually simpler when you already have all the values.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Avoid two common assignment mistakes

  • items[index] = values replaces one existing element with the whole values object. It does not insert the iterable’s contents as separate elements. Use items[index:index] = values when you want insertion.
  • Do not assign the result of insert, extend, or slice assignment back to the list. These operations mutate the existing list; list methods such as insert and extend return None, rather than the modified list. This follows Python’s documented convention for mutable data structures in the list-method tutorial.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use a deque for a queue that changes at both ends

Inserting repeatedly at the beginning of a list requires shifting the other elements. If your data structure needs frequent appends and removals at both ends, Python’s tutorial recommends collections.deque for that queue pattern rather than using a list as a front-insertion queue. See the Python 3.11 tutorial’s queue guidance.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.