def create_table(m, n):
matrix = [[1]*(m) for x in range(n)]
return matrix
def fill_table(m, n, table):
pom = []
pom.extend(table)
print(pom is table) #just to be sure they aren't same object
for i in range (m):
for j in range (n):
pom[i][j] = j+1
return pom
def main():
table1=[]
table1=create_table(4,4)
table2=fill_table(4,4,table1)
for i in range (4): print(table1[i])
print("------------")
for i in range (4): print(table2[i])
if __name__=="__main__": main()
So when I print these tables I get this:
False [1, 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 4] ------------ [1, 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 4]
I don't understand how table1 gets filled with same data as table2, even though I don't manipulate with table1's anywhere and they aren't even same object? Or do I?


Sign In
Create Account

Back to top









