⊕
⊖
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.
Output
[[], [], [], [], []]
2. Create a list of 10 empty lists
In the following example, we create a list with 10 empty lists as elements.
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.
Next Topic ⫸ Python List – Access elements
⫷ Previous Topic Python – Create a list of objects