Creating lists is a core part of working with Python, and while square brackets ([]) are the most common way to define a list, Python also provides a powerful and flexible alternative — the list() constructor.
This built-in function allows you to create new lists from a wide variety of iterable objects, making it especially useful when transforming or converting data.
1. What Is the list() Constructor in Python?
The list() constructor is a built-in Python function that creates a new list from any iterable, such as a:
- string
- tuple
- set
- range
- dictionary (keys, values, or items)
It serves as an alternative to using square brackets and is particularly valuable when converting one data type into a list format. Since many operations — like sorting, slicing, filtering, or updating — work best on lists, this constructor becomes an essential tool in Python programming.
2. Purpose of Using list()
Using the list() constructor is helpful when you want to:
- Convert an iterable into a list
- Transform data before applying list methods
- Work with sequences that don’t naturally start as lists
- Create dynamic lists from functions or generated values
- Initialize an empty list when no iterable is provided
- Initialize an empty list when no iterable is provided
In short, list() gives you a clean, predictable way to turn almost anything iterable into a list you can manipulate freely.
3. Syntax of the list() Constructor
list(iterable)
If no iterable is passed, the constructor simply returns an empty list.
4. Parameter Description
| Parameter | Description |
|---|---|
| iterable | Any iterable object (e.g., string, tuple, set, dictionary, range). Optional — if omitted, list() creates an empty list. |
5. Python list() Constructor – Practical Examples
The list() constructor can transform different types of iterables into list objects, making it one of the most flexible tools in Python. Below are clear, real-world examples showing how it works with various data types.
Example 1. Creating an Empty List
empty_list = list()
print(empty_list)
#Output:
[]
empty_list = list()
print(empty_list)
#Output:
[]
Explanation:
Indexing gives you precise, instant access to any list item—perfect for selecting details, slicing sections, or controlling logic based on specific positions.
Example 2. Converting a String to a List of Characters
char_list = list("hello")
print(char_list)
#Output:
['h', 'e', 'l', 'l', 'o']
char_list = list("hello")
print(char_list)
#Output:
['h', 'e', 'l', 'l', 'o']
Explanation:
Each character in the string becomes a separate list element. This is useful for text processing and character manipulation.
Example 3. Converting a Tuple to a List
tuple_data = (10, 20, 30)
list_from_tuple = list(tuple_data)
print(list_from_tuple)
#Output:
[10, 20, 30]
tuple_data = (10, 20, 30)
list_from_tuple = list(tuple_data)
print(list_from_tuple)
#Output:
[10, 20, 30]
Explanation:
The constructor converts every element from the tuple into a list item, making the data mutable and easier to modify.
Example 4. Converting a Set to a List
set_data = {1, 2, 3}
list_from_set = list(set_data)
print(list_from_set)
#Output:
[1, 2, 3]
set_data = {1, 2, 3}
list_from_set = list(set_data)
print(list_from_set)
#Output:
[1, 2, 3]
Explanation:
The unordered items from the set are converted into a list.
Note: The order of elements may vary because sets do not maintain insertion order.
Example 5. Converting a Dictionary to a List of Keys
dict_data = {'a': 1, 'b': 2}
list_from_dict = list(dict_data)
print(list_from_dict)
#Output:
['a', 'b']
dict_data = {'a': 1, 'b': 2}
list_from_dict = list(dict_data)
print(list_from_dict)
#Output:
['a', 'b']
Explanation:
When a dictionary is passed to list(), only its keys are converted into a list. This is the default behavior in Python.
Example 6. Converting a Range to a List
range_obj = range(5)
list_from_range = list(range_obj)
print(list_from_range)
#Output: [0, 1, 2, 3, 4]
Explanation:
Every number generated by the range() function becomes an element in the list — great for creating sequences.
Example 7. Copying an Existing List Using list()
original = [1, 2, 3] copied = list(original) print(copied) #Output: [1, 2, 3]
Explanation:
Using list() on an existing list creates a shallow copy. This is a clean and safe way to duplicate a list without modifying the original.