0

I am cycling through all the possible numerical combinations of an array like this:

positions = [[0]*length]
for i in range(length):
    for j in range(1,10):
        positions[i] = j
    positions[i] = 0

This by itself is working fine, however it stops working when I make it into a function and return the result like this:

def funct():
   arr = []
   positions = [[0]*length]
   for i in range(length):
       for j in range(1,10):
           positions[i] = j
           arr.append(positions)
           print(positions)
       positions[i] = 0
   return arr

Strangely enough, all the print-outs show it working fine as in the first example. However, the returned array is full of arrays which are just sets of 0s like [0,0,0].

What's causing this difference?

frog_prog
  • 39
  • 3

0 Answers0