n dimensional array creator in Python Is there any way I can make this function more inline?

def nDimensionalArray(n, s):
    x = 0
    for i in range(n):
        x = [x for j in range(s[i])]
    return x
You didn't write a docstring (which you should have done) or explain your function (which you should also have done), but it looks like n is supposed to be the same as the length of s.  If so, why should n have to be specified?

Your function has some unintuitive behaviour:

&gt;&gt;&gt; matrix = nDimensionalArray(3, [1,2,3])
&gt;&gt;&gt; matrix
[[[0], [0]], [[0], [0]], [[0], [0]]]
&gt;&gt;&gt; matrix[0][0][0] = 1
&gt;&gt;&gt; matrix
[[[1], [1]], [[1], [1]], [[1], [1]]]


Changing one element changes everything!  I assume that that is unintentional.  If it is intentional, then it needs to be clearly documented.