I am just playing along with python to understand the things in more depth.
I learned that One of the easier ways is to use zip
, but how about this:
>>> a = [[1,1,1], [2,2,2], [3,3,3]]
>>> for i in range(len(a)):
... for j in range(len(a[0])):
... a[i][j], a[j][i] = a[j][i], a[i][j]
...
>>> a
[[1, 1, 1], [2, 2, 2], [3, 3, 3]]
>>>
well, I was expecting the answer to be
[[1, 2, 3], [1, 2, 3], [1, 2, 3]]
because that is what Transpose would be ? I swapped the elements, right?? Also, this way was more natural to me. I read the documentation for zip here and it does not say anything about such "tricks". How to learn these more pythonic ways of doing the things? I am aware that asking for resources to learn goes into subjective choices and SO does not encourage such questions. But IMO, it is clearly not a matter of choice in this case, but finding any and every resource where such information is available.