I'm trying to print an n*n matrix with only the forward diagonal elements set to True and the rest to False.
Here is my code:
def func(n):
dp = [[False]*n]*n
for i in range(n):
dp[i][i] = True
print(dp)
I'm baffled as to why the True values are spreading through the entire matrix instead of remaining confined to the cells where i=j.
Desired output for n=5:
True False False False False
False True False False False
False False True False False
False False False True False
False False False False True
Current output for n=5:
True True True True True
True True True True True
True True True True True
True True True True True
True True True True True
What could be the issue here?