I basically want a Python equivalent of this Array in C:
JavaScript
x
2
1
int a[x];
2
but in python I declare an array like:
JavaScript
1
2
1
a = []
2
and the problem is I want to assign random slots with values like:
JavaScript
1
2
1
a[4] = 1
2
but I can’t do that with Python, since the Python list is empty (of length 0).
Advertisement
Answer
If by “array” you actually mean a Python list, you can use
JavaScript
1
2
1
a = [0] * 10
2
or
JavaScript
1
2
1
a = [None] * 10
2