a = [[1,2,3],[4,5,6],[7,8,9]] col = [x[1] for x in a] print col
This code prints out the values of the 2nd column. But I don't understand how the List comprehension expression works.
Doesn't x[1] obtain the value of the 2nd row ? Very confused =/




Posted 05 October 2014 - 01:39 AM
a = [[1,2,3],[4,5,6],[7,8,9]] col = [x[1] for x in a] print col
Posted 05 October 2014 - 03:06 AM
This post has been edited by sepp2k: 05 October 2014 - 03:07 AM
