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