I have this code that is progressively generating a larger multidimensional array recursively.
def lex(stop,n = 2,array = [[0,0],[1,-1]]):
if n == 2:
if stop == 2:
return array
else:
return lex(stop,n+1,array)
else:
newArray = []
for x in range(n):
for y in range(len(array)):
newArray.append(array[y][:])
for x in range(len(newArray)):
pos = x // factorial(n-1)
newArray[x].insert(pos,-pos)
for y in range(pos):
if y < x: newArray[x][y] += 1
if n == stop:
print(newArray)
return newArray
else:
lex(stop,n+1,newArray)
The strange part is at the end in the if n == stop
block. print(newArray
prints the correct array but the return
statement doesn't seem to work. Any attempt at printing the result just shows None
.
Is there something functionally wrong with how I'm returning the array?