Python – Create a list of empty lists

Create a List of Empty Lists

To create a list of empty lists in Python, multiply the empty list of an empty list, by the number n, where n is the required number of inner lists.

[[]] * n

The above expression returns a list with n number of empty lists.

Examples

1. Create a list of 5 empty lists

In the following example, we create a list of 5 empty lists.

Python Program

n = 5
output = [[]] * n
print(output)
Run Code Copy

Output

[[], [], [], [], []]

2. Create a list of 10 empty lists

In the following example, we create a list with 10 empty lists as elements.

Python Program

n = 10
output = [[]] * n
print(output)
Run Code Copy

Output

[[], [], [], [], [], [], [], [], [], []]

Summary

In this tutorial of Python Examples, we learned how to create a list of size n where the elements of the list are empty lists, with the help of examples.

Related Tutorials

Code copied to clipboard successfully 👍