I need to create a list as a function of two variables, but the output from that list is different from the output from another list created manually (both list are equal).
Here is the code:
from math import factorial
n=4
k=3
ntuples=int(factorial(n-1)/factorial(k-1))
B=[[1]*k]*ntuples
A=[[1,1,1],[1,1,1],[1,1,1]]
print(A==B)
m=0
n=0
for i in range(len(A)):
A[i][m]=A[i][m]+1
m+=1
for j in range(len(B)):
B[j][n]=B[j][n]+1
n+=1
print(A)
print(B)
output:
True
[[2, 1, 1], [1, 2, 1], [1, 1, 2]]
[[2, 2, 2], [2, 2, 2], [2, 2, 2]]
I want to get the output of A, but using B list. What am I doing wrong? Thanks!