close

How to create a list of empty lists

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to create a list of empty lists in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to create a list of empty lists?

  1. How to create a list of empty lists?

    For arbitrary length lists, you can use [ [] for _ in range(N) ]
    Do not use [ [] ] * N, as that will result in the list containing the same list object N times

  2. create a list of empty lists

    For arbitrary length lists, you can use [ [] for _ in range(N) ]
    Do not use [ [] ] * N, as that will result in the list containing the same list object N times

Method 1

For arbitrary length lists, you can use [ [] for _ in range(N) ]

Do not use [ [] ] * N, as that will result in the list containing the same list object N times

Method 2

For manually creating a specified number of lists, this would be good:

empty_list = [ [], [], ..... ]

In case, you want to generate a bigger number of lists, then putting it inside a for loop would be good:

empty_lists = [ [] for _ in range(n) ]

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read