Similar to other programming languages like C/C++, in Python do we have a way of declaring an array without initializing (something like data[1][3]
)? Here I have a snippet that creates an empty 2D list:
data=[[]]
data[0]=[1,2,3]
data[1]=[3,4,5] //this will create an error since its out of bound access
In my case, I want to define the number of rows and columns statically. I believe the append()
API may help but what can help me better is the traditional way of initializing (since my input data to be copied from elsewhere). I believe, if I can specify the sizes in data[[]]
, it will solve the problem.