How do I prepend to a short python list?
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
If the list is short, prepending in Python is mostly about choosing the clearest expression rather than chasing tiny performance gains. Python lists do not have a dedicated prepend() method, but the language gives you a few good options depending on whether you want to mutate the original list or create a new one.
The Normal In-Place Solution: insert(0, value)
The standard way to add one item to the front of an existing list is insert.
Output:
This mutates the list in place, which is usually exactly what you want when the list already belongs to the current piece of code.
Under the hood, Python shifts the existing elements to the right. That makes prepending less efficient than append(), but for small lists the difference rarely matters.
Create A New List With Concatenation
If you want to keep the original list unchanged, build a new list instead.
Output:
This version is often clearer in functional-style code or when the prepend happens inside an expression.
Prepending Several Values
If you need to add multiple items to the front while preserving their order, slice assignment is convenient.
Output:
This is more readable than calling insert(0, value) repeatedly, and it avoids accidentally reversing the prepended items.
You can also create a new list if mutation is not desired:
When deque Is The Better Data Structure
The question says the list is short, so a regular list is fine. Still, it is worth knowing when the requirement changes. If your algorithm prepends frequently, collections.deque is designed for efficient operations at both ends.
A deque is a better structural choice when left-end insertion is a core operation rather than an occasional convenience.
Pick The Method By Intent
A useful rule of thumb is:
- use
insert(0, value)when you want to mutate the current list - use
[value] + itemswhen you want a new list - use
items[:0] = valueswhen adding several leading values - use
deque.appendleft()when front insertion is frequent enough to matter structurally
For a short list, readability should drive the choice more than raw complexity analysis.
Common Pitfalls
The most common mistake is over-optimizing a tiny list. If the list has only a few elements, insert(0, value) is almost always fine and much clearer than changing data structures prematurely.
Another issue is choosing concatenation when callers expect the original list to be modified. That silently creates a new list and leaves the old one untouched.
Repeated insert(0, value) calls can also reverse the order you intended if you are not careful. If you need to prepend several items, do it in one step with slice assignment or concatenate a list of the new values.
Finally, if prepending becomes a hot path, do not keep forcing a list to behave like a queue. Switch to deque and make the algorithm's intent explicit.
Summary
- For a short list,
insert(0, value)is the normal prepend operation. - Use concatenation when you want a new list instead of mutating the old one.
- Use slice assignment to prepend multiple values cleanly.
- Choose
dequeonly when front insertions are frequent enough to justify a different structure. - For small lists, clarity matters more than micro-optimization.
Related reading
- How do I prevent malicious DHT clients that might want to alter/delete my DHT data?
- How do I print the full NumPy array, without truncation?
- How do I print the full NumPy array, without truncation?
- How do I print the key-value pairs of a dictionary in python
- How do I prevent Conda from activating the base environment by default?
- How do I print an exception in Python?
- How do I read CSV data into a record array in NumPy?
- How do I remove duplicates from a list, while preserving order?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.