Why is faster than 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.
In Python, lists can be created using two distinct approaches: the bracket syntax [] and the list() function. Although both methods yield a list object, there is a noticeable difference in their performance. The bracket syntax is generally faster than the list() function. This article delves into the technical reasons behind this performance discrepancy, provides examples, and discusses additional related topics.
Technical Explanation
1. Syntax and Execution
- Bracket Syntax
[]:- The bracket syntax is a part of Python's core syntax. It directly translates into a list at the interpreter level.
- When you use
[]to create a list, it's a straightforward operation that involves minimal overhead. The interpreter knows that[]is a list and doesn't have to do any additional work to figure this out. - It simply allocates memory for an empty list and returns it.
list()Function:- The
list()function is a built-in Python function. When called, it involves a function call overhead. - Internally, the
list()function is implemented in C, but invoking any function entails additional steps for setting up the stack frame and passing parameters, which slightly slows down execution. - The function must be parsed and evaluated, and its execution involves additional layers compared to direct syntax-based creation.
2. Performance Comparison
The performance benefit of using [] becomes evident when creating lists in code that requires optimal execution speed, such as in loops or recursive functions. Below is a simple comparison using the timeit module to measure the execution time for creating an empty list using both methods.
- Use
[]when you need to quickly initialize empty lists, particularly in performance-critical code sections, such as in loops or recursive functions. - Consider
list()when converting other iterables into a list. It is explicitly designed for this purpose, and though it is slower when creating empty lists, it excels in conversions. []offers a clean and concise way to declare lists.list()can sometimes improve readability especially when converting iterables like sets or tuples to lists.
Related reading
- Why is Git not considered a block chain?
- Why is HashSetPoint so much slower than HashSetstring?
- Why is Insertion sort better than Quick sort for small list of elements?
- Why is it impossible to find a specified value in a sorted array faster than Olog n?
- Why is float division slow?
- Why is i-- faster than i in loops?
- Why is if not someobj better than if someobj None in Python?
- Why is import bad?

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.