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<rows:
    selectCols=grid[i][colID]
    i+=1
    arr2.append(selectCols)

print "col",colID,"values :",arr2

----->colID is the value of the requested column to print. which remains the
same throughout the iteration of while.


On 9/2/07, Alan Gauld <[EMAIL PROTECTED]> wrote:
>
>
> "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.
>
> > 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[4] for row in grid]
>
> HTH,
>
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Varsha Purohit,
Graduate Student,
San Diego State University
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to