Varsha Purohit wrote:
> Thanks Eric and Alan i did that with while loop. I donno i was getting
> an error while using a for loop for subindexing. Here is what i did
>
> i=0
> selectCols=0
> arr2=[]
> while i selectCols=grid[i][colID]
> i+=1
> arr2.append(selectCols)
>
> print "col"
Thanks Eric and Alan i did that with while loop. I donno i was getting an
error while using a for loop for subindexing. Here is what i did
i=0
selectCols=0
arr2=[]
while icolID is the value of the requested column to print. which remains the
same throughout the iteration of while.
On 9/2/07, Ala
"Varsha Purohit" <[EMAIL PROTECTED]> wrote
> 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]]
You don't need the '\' characters, the fact that the closing
bracket has not been reached means Python will ignore
the newline characters.
> ho
>
> COL = 5
> [i[COL-1] for i in grid]
Should have guessed...
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
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,
> 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]...
Your basic tool is sub-indexing: you can reach items in the sub-lists
by us
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]...
thanks,-
Varsha Purohit,
__
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]...
thanks,-
Varsha Purohit,
__