[Tutor] Slices of lists of lists

spir denis.spir at gmail.com
Fri Mar 28 20:03:53 CET 2014


On 03/28/2014 10:42 AM, Jose Amoreira wrote:
> [...]  If we want to access individual rows of this matrix like
> object, the standard slice notation (on the second index) works as expected also:
>
> In [3]: l[0][:]
> Out[3]: [11, 12, 13]
>
> In [4]: l[1][:]
> Out[4]: [21, 22, 23]
>
> Again, fine!

No! You *made* here *copies* of the rows. To *get* the rows themselves as they 
are, just type:
     l[index_of_row]

Also note the following: thinking in terms of row/column is very much 
misleading. The row number/index is actually the "vertical"(y or j) coordinate, 
and the column index is a horizontal coordinate... Thus, if you to think that 
way, speak of "columns & rows"! not the other way round. This means that, if you 
want yourself or a user to write down a matrix (or eg a game board or map), they 
would have to inverse their logic; or you would have to reverse the map (your 
other question).

d


More information about the Tutor mailing list