Python 3 turn range to a 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
In Python 3, range() returns a range object, not a list. If you need a real list, the idiomatic conversion is list(range(...)), but it is worth understanding when that conversion is useful and when it is just unnecessary memory allocation.
The Direct Conversion
The normal answer is short:
Output:
The same works with explicit start, stop, and step values:
That produces:
So if the question is literally "how do I turn a range into a list," that is the answer.
Why Python 3 Does Not Return a List Automatically
Python 2 returned a list from range(), but Python 3 changed the behavior to avoid creating large lists unnecessarily. A range object stores only the arithmetic pattern and computes values lazily when needed.
That object can represent one million numbers without building a one-million-element list in memory.
When a List Is Actually Needed
Convert a range when you need list behavior, for example:
- modifying elements
- appending new items
- passing the result to code that specifically expects a list
- serializing or printing the complete materialized sequence
You cannot do those operations directly on a range object because it is immutable and does not have list methods.
Things You Can Do Without Conversion
A lot of Python beginners convert too early. Many common operations already work on range directly.
Iteration works:
Membership tests work:
Indexing works:
Slicing works too, and the result is another range object:
Because of that, converting immediately is often just habit rather than necessity.
Descending Ranges and Other Variants
Negative steps are handled exactly the same way:
You can also reverse a range explicitly:
Both are fine. Use whichever expression makes the intention clearer.
List Comprehensions Are Different
Developers sometimes write a list comprehension where a direct list conversion would be simpler:
That works, but it is doing more work than necessary if you are not transforming the values. Prefer:
Use a comprehension only when you need to map or filter:
Common Pitfalls
- Converting a huge range to a list can consume large amounts of memory for no real benefit.
- Carrying over Python 2 assumptions leads to confusion because Python 3
rangeis not a list. - Using a list comprehension just to copy the range values is unnecessary when
list(range(...))is clearer. - Repeatedly converting inside a loop adds needless allocation cost.
- Forgetting that many built-in functions such as
sum,min, andmaxalready accept arangedirectly leads to extra work.
Summary
- In Python 3, use
list(range(...))to materialize a range as a list. - '
range()itself returns a compact iterable object, not a prebuilt list.' - Convert only when you actually need list semantics.
- Iteration, indexing, slicing, and membership checks already work on
range. - Avoid large or repeated conversions unless there is a clear reason to materialize the sequence.
Related reading
- Python add item to the tuple
- Python Convert complex dictionary of strings from Unicode to ASCII
- Python creating a dictionary of lists
- Python csv string to array
- Python 3 type hinting for None?
- Python + Distributed - Is it possible using Dask to utilize a set of workers to apply a function to seperate files from a folder concurrently
- Python data structure sort list alphabetically
- Python dataclass from a nested dict

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.