My question is related to this question. I was trying to model the list comprehension provided by @shuttle87 in his/her answer to the question to a regular old-fashioned loop. Here is what my code snippet looks like:
matrix = [[2,0,2],[0,2,0],[2,0,2]]
sqd = []
for i in matrix:
for e in i:
sqd.append(e*e)
print(sqd)
My problem is that my code returns a list i.e., [4, 0, 4, 0, 4, 0, 4, 0, 4] instead of a matrix i.e., [[4, 0, 4], [0, 4, 0], [4, 0, 4]]. What can i be possibly doing wrong?
disclaimer: I am aware there are wonderful python libraries that can do this for e.g., numpy. I like understanding things through intuition and thus this question...so forgive my naivety.