I know how to declare an empty array of a certain size, say 25 lists in it -
mylist = [[] for _ in range(25)]
But if I don't know the size yet, how to define it? Obviously this following doesn't work -
mylist = [[] for _ in range(math.inf)]
The reason I'm asking is that I need to assign value to some items in the list. For example -
mylist[1].append(87)
But it'll show an "index out of range
" error if I simply declare an empty list in the beginning, i.e.
mylist = [[]]
I guess it's because I'm trying to access the second element, whereas even the first element doesn't exist yet.
Thank you in advance