Python Reference Library →

Python list() Function – Convert Data to a List

Let’s look at list() function – convert data to a list

  1. Notice

    list() builds a mutable list from an iterable. Constructing a list from text gives one element per character.

  2. Try

    Follow the example, change its sample, and compare what happens.

  3. Check

    Explain the result and test your understanding.

Watch how it works

Focus on how the names, objects, and calculations change. We’ll inspect the printed output in the next section.

Explore the idea

Follow the code and watch its state change. Guided simulation.

Code
Python
text = 'tea'
items = list(text)
print(items)
Live state

Top-level scope

text→Object 1
items→Object 2
Object 1 · str'tea'Object 2 · list['t', 'e', 'a']
This step

list() builds a mutable list from an iterable. Constructing a list from text gives one element per character.

Picture list() function – convert data to a list

list() builds a mutable list from an iterable. Constructing a list from text gives one element per character.

Image brief

Alt text
A diagram for Python list() Function – Convert Data to a List. Instructions: text = 'tea' items = list(text) print(items). Displayed result: ['t', 'e', 'a']. The final example bindings are text --> object 1 (str); items --> object 2 (list). object 1: 'tea'; object 2: ['t', 'e', 'a']
Image generation prompt
Create a clean educational illustration for a Python programming lesson titled "Python list() Function – Convert Data to a List". Teaching focus: list() builds a mutable list from an iterable. Constructing a list from text gives one element per character. Depict exactly the relationships and labels in this reference diagram: EXAMPLE INSTRUCTIONS text = 'tea' items = list(text) print(items) | v DISPLAYED RESULT ['t', 'e', 'a'] FINAL BINDINGS text --> object 1 (str) items --> object 2 (list) object 1: 'tea' object 2: ['t', 'e', 'a'] Use a flat vector style, generous spacing, clear arrows and legible labels, with a restrained blue/teal palette on a plain background. The diagram must explain the programming idea accurately. Do not depict variables as boxes containing copied objects when they share a reference. Avoid mascots, decorative screenshots, logos, gradients and extra text. Landscape composition, approximately 3:2, suitable for a course card. Accessible description: A diagram for Python list() Function – Convert Data to a List. Instructions: text = 'tea' items = list(text) print(items). Displayed result: ['t', 'e', 'a']. The final example bindings are text --> object 1 (str); items --> object 2 (list). object 1: 'tea'; object 2: ['t', 'e', 'a']

Follow the execution

Choose a different sample input, then follow every step through to the output. Before revealing it, predict what the program will display.

Execution workspace

Choose a sample and follow its execution. Guided simulation.

Code
Python
text = 'tea'
items = list(text)
print(items)
Live state

Top-level scope

text→Object 1
items→Object 2
Object 1 · str'tea'Object 2 · list['t', 'e', 'a']
This step

The example has finished. Compare the final output with the values and references above.

Terminal
Output
['t', 'e', 'a']

What do you expect this program to print?

What does this example display?

text = 'tea'
items = list(text)
print(items)
What does this example display?
Choose one answer. You can try again.

Answer and explanation

['t', 'e', 'a']

Follow the printed values in order. The output is: ['t', 'e', 'a']

More examples and reference

Python list() Function

The list() function in Python is used to create a new list. It can also be used to convert other iterable data types like strings, tuples, or sets into a list.

Syntax

list([iterable])

Parameters:

  • iterable (optional) – An iterable object like string, tuple, set, or dictionary.

Returns:

  • A new list containing items from the given iterable.

Example 1: Creating an Empty List

my_list = list()
print(my_list)
[]

Example 2: Converting a String to a List

my_list = list("hello")
print(my_list)
['h', 'e', 'l', 'l', 'o']

Example 3: Converting a Tuple to a List

my_list = list((1, 2, 3))
print(my_list)
[1, 2, 3]

Example 4: Converting a Set to a List

my_list = list({10, 20, 30})
print(my_list)
[10, 20, 30]  

Example 5: Converting a Dictionary to a List

my_dict = {'a': 1, 'b': 2}
my_list = list(my_dict)
print(my_list)
['a', 'b']

Note: Only the keys of the dictionary are added to the list.

Use Cases

  • Convert data types like tuples or sets to a list for modification
  • Split a string into a list of characters
  • Convert dictionary keys into a list for iteration

Common Mistakes

  • list is not a function call: Forgetting parentheses: my_list = list assigns the function, not a list.
  • Non-iterable input: list(5) will throw TypeError because int is not iterable.

Interview Tip

In interviews, the list() function is often used to convert generators or iterators to lists for easier access and manipulation.

Summary

  • list() creates a list from an iterable or creates an empty list.
  • Commonly used to convert other data types to a list.
  • Only iterable objects can be passed.

Practice Problem

Convert the string "Tutorial" into a list of characters, and print it.

word = "Tutorial"
letters = list(word)
print(letters)

What to remember

Connect what you noticed in the example with the idea below.

Remember

list() builds a mutable list from an iterable. Constructing a list from text gives one element per character.

Watch out for this idea

list(text) always makes a single-element list containing the full text.

This is the misconception to avoid.

Reference checks are optional and do not count toward course progress.

    Reference library →