Is there a way in Python to initialize a multi-dimensional array / list without using a loop?
Advertisement
Answer
Sure there is a way
JavaScript
x
2
1
arr = eval(`[[0]*5]*10`)
2
or
JavaScript
1
2
1
arr = eval(("[[0]*5]+"*10)[:-1])
2
but it’s horrible and wasteful, so everyone uses loops (usually list comprehensions) or numpy