This doesn't seem to have been answered... "Shi Mu" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >I can not understand the use of "cell in row" for two times in the code: > > # convert the matrix to a 1D list > matrix = [[13,2,3,4,5],[0,10,6,0,0],[7,0,0,0,9]] > items = [cell for row in matrix for cell in row] > print items
Lets expand the list comprehension: matrix = [[13,2,3,4,5],[0,10,6,0,0],[7,0,0,0,9]] items = [] for row in matrix: for cell in row: items.append(cell) print items Does that explain whats going on? Its just nesting another for loop. HTH, -- Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor