+ 1

Lists in List (Python)

Hello Guys, i want to initialize Lists in a List, so i want it to look like this [[],[],...] but i want the amount of lists in the list to have a specific length of course. Is there a faster way than to initialize the big list and then append all the small lists? greeting and thanks for the help

31st Oct 2019, 7:58 AM
Long Kiet Nguyen
Long Kiet Nguyen - avatar
1 Respuesta
+ 3
You can use a list comprehension to put a certain number of elements (in this case, empty lists) into a collection list_of_lists = [[] for _ in range(10)] print(list_of_lists)
31st Oct 2019, 8:35 AM
Tibor Santa
Tibor Santa - avatar