Get Kth Column of Matrix using list comprehension

test_list = [[4, 5, 8], [8, 1, 20], [7, 12, 10]]

print("The original list is : " + str(test_list))

K = 2

res = [sub[K] for sub in test_list]

print("The Kth column of matrix is : " + str(res))


No comments: