If you have access to numpy,
import numpy as np
a_transposed = a.T
# Get first row
print(a_transposed[0])
The benefit of this method is that if you want the "second" element in a 2d list, all you have to do now is a_transposed[1]
. The a_transposed
object is already computed, so you do not need to recalculate.
Finding the first element in a 2-D list can be rephrased as find the first column in the 2d list. Because your data structure is a list of rows
, an easy way of sampling the value at the first index in every row is just by transposing the matrix and sampling the first list.