+ 1

How to create a list with a defined lenght?

How can I create an empty list with a defined lenght, so I don't get an error when assigning a value to an specific slot?

25th Oct 2018, 9:50 PM
Ever De La Ossa
Ever De La Ossa - avatar
3 Antworten
+ 3
x = given by you list = [0 for i in range(x)] or list = [0]*x or list = list(range(x))
25th Oct 2018, 9:54 PM
Mbrustler
Mbrustler - avatar
+ 2
you're welcome:)
25th Oct 2018, 10:00 PM
Mbrustler
Mbrustler - avatar
+ 1
Mbrustler thanks for your explanation :) I aprecciate it!
25th Oct 2018, 10:00 PM
Ever De La Ossa
Ever De La Ossa - avatar