How to access elemenst in a list of lists?
Algis Kabaila
akabaila at pcug.org.au
Mon May 9 20:44:28 EDT 2011
On Tuesday 10 May 2011 05:24:16 Terry Reedy wrote:
> On 5/9/2011 4:25 AM, Antonio CHESSA wrote:
> > apple =
> > [["a","b","c"],[1,2,3,4,5,6],["antony","max","sandra","seb
> > astian"]]
> > for j in range (len(apple[i])):
> > print apple[i][j]
>
> While this illustrate double indexing, it can be simplified
> to
>
> for top in apple:
> print(top)
> for inner in top:
> print(inner)
>
> and give the same output. Indexing is only needed for random
> access and for changing a list in place.
The method of double indexing in the manner
apple[i][j]
or
a[i][j]
for the (i, j) -th element of multi-dimensional array is well
known and widely used. But how to enable the "standard" matrix
notation
a[i, j]
in Python 3.2 in the manner of numpy (and other matrix
packages)? Is it subclassing of "special methods"
__getitem__()
and/or
__setitem__()
and if so how?
OldAl.
--
Algis
http://akabaila.pcug.org.au/StructuralAnalysis.pdf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110510/6b5ad8ea/attachment-0001.html>
More information about the Python-list
mailing list