megaList = []
clmsArrow = [[3],[2,3,4],[1,3,5],[3],[3],[3],[3]]
def columnState(y,amnt):
"-1 for all values in a list of lists"
megaList.append(y)
print(y)
for i in range(len(y)):
for j in range(len(y[i])):
y[i][j] -= 1
if y[i][j] == 0:
y[i][j] = 5
if amnt != 1:
return columnState(y,amnt-1)
columnState(clmsArrow,5)
print('\n')
for x in megaList:
print(x)
''Output''
[[3], [2, 3, 4], [1, 3, 5], [3], [3], [3], [3]]
[[2], [1, 2, 3], [5, 2, 4], [2], [2], [2], [2]]
[[1], [5, 1, 2], [4, 1, 3], [1], [1], [1], [1]]
[[5], [4, 5, 1], [3, 5, 2], [5], [5], [5], [5]]
[[4], [3, 4, 5], [2, 4, 1], [4], [4], [4], [4]]
[[3], [2, 3, 4], [1, 3, 5], [3], [3], [3], [3]]
[[3], [2, 3, 4], [1, 3, 5], [3], [3], [3], [3]]
[[3], [2, 3, 4], [1, 3, 5], [3], [3], [3], [3]]
[[3], [2, 3, 4], [1, 3, 5], [3], [3], [3], [3]]
[[3], [2, 3, 4], [1, 3, 5], [3], [3], [3], [3]]
Why can't I write out to global variable (list) properly? All I get is the same first function input times five
As seen in the output inside function everything is alright, but when I try to add the same variable to a list outside the function something goes wrong
global megaList(which you also need to define, before you go into function, as an empty list I suppose)megaLista class attribute. This means you don't have to use a global, and all methods in the class can access it.megaList = 'whatever')