Convert Range into a List
To convert given range object into a list in Python, call list() builtin function and pass the given range object as argument. list() function returns a new list with the elements from the range object.
The syntax to convert given range object
a into a list
output = list(a)
In the following example, we take a range object starting at 4, and progressing upto 10 (excluding 10), and convert this range object into a list.
#take a range a = range(4,10) #convert range object into list output = list(a) print(output)
[4, 5, 6, 7, 8, 9]
In this tutorial of Python Examples, we learned how to convert a range object into a list using list() builtin function.
- Shuffle Python List
- Python – Get Index or Position of Item in List
- Python Program to Find Smallest Number in List
- How to Get List of all Files in Directory and Sub-directories?
- How to Access List Items in Python?
- How to Insert Item at Specific Index in Python List?
- Python List without Last Element
- Python List of Functions
- Python – List of Strings
- Python Program to Find Duplicate Items of a List