Contents
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 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 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
- Python – Traverse List except Last Element
- Python List of Functions
- Python Program to Find Smallest Number in List
- Python List – Add Item
- Python – List of Strings
- Python Program to Find Duplicate Items of a List
- Python – How to Create an Empty List?
- Python List of Dictionaries
- How to Sort Python List?
- Python Program to Find Largest Number in a List