[Tutor] Accessing Values of specific column in a 2D list or array
alan.gauld at btinternet.com
Sun Sep 2 16:10:54 CEST 2007
"Varsha Purohit" <varsha.purohit at gmail.com> wrote
> grid = [[1,1,2,7,6,9],\
You don't need the '\' characters, the fact that the closing
bracket has not been reached means Python will ignore
the newline characters.
> how can i access to all the elements of the list from column no. 5.
> output should be like [6,9,0,8]...
Others have already shown but the easiest way to build a list
from another list is via a list comprehension so:
col5 = [row for row in grid]
Author of the Learn to Program web site
More information about the Tutor