[Tutor] Accessing Values of specific column in a 2D list or array

Ricardo Aráoz ricaraoz at gmail.com
Sun Sep 2 12:45:32 CEST 2007


Varsha Purohit wrote:
> 
> 
> Hello,
>     Suppose i have a 2D list(grid) like
> 
> grid = [[1,1,2,7,6,9],\
>           [,9,1,1,1,9,1],\
>           [8,1,2,0,0,4],\
>           [1,4,1,1,8,5]]
> 
> how can i access to all the elements of the list from column no. 5.
> 
> output should be like [6,9,0,8]...
> 

COL = 5
[i[COL-1] for i in grid]



More information about the Tutor mailing list