Indexing list of lists

Hilde Roth hildegarde_roth at yahoo.de
Thu Sep 18 13:50:46 EDT 2003


> Like it or not, there are no "different dimensions", just lists of lists 
> of lists... 

You are being too litteral. A list of list is like a 2D array from an
indexing point of view, a list of lists of lists like a 3D array etc.
E.g., (((1,10),(2,20),(3,30)),((-1,'A'),(-2,'B'),(-3,'C'))) is a  
2 x 3 x 2 rectangular data structure and has 3 dimensions. Hence,
e.g., l[0;2;1] ~ l[0][2][1] = 30

> [alist[2], alist[-3], alist[7]] and [alist[i] for i in [2, -3, 7]] 

I agree that comprehensions alleviate the problem to an extent. 
However the first notation is definitely cumbersome for all but the
shortest index lists.

> It covers the most common cases of list item extraction with a concise
> syntax.

Maybe but 
1/ it is more or less redundant: the (x)range syntax could have been 
   extended with the same effect
2/ it lacks generality since it can only generate arithmetic progressions

Hilde




More information about the Python-list mailing list