list of lists

Dave Kuhlman dkuhlman at rexx.com
Tue Sep 16 19:30:57 CEST 2003


Tom wrote:

> Hi guys,
> 
> thanks to everyone.
> My mistake was that I had no idea that writing [][] NEXT to each
> other goes into depth. I always tried different varieties of [[]]
> to get into the deeper lists!
> Thanks again.

It's a simple concept, once you grasp it, but for those new to
Python, it may be worth emphasizing -- You can concatenate
operators (to the right, at least) and these operators will
operate on the run-time value produced by the expression
to which they are applied.  For example (read from bottom up):


    getArray()[3].formatter()
       ^    ^  ^ ^          ^
       |    |  | |          |
       |    |  | |          +--- (5) call function retrieved from
       |    |  | |                   attribute
       |    |  | +-------------- (4) access attribute of object indexed
       |    |  |                     from array
       |    |  +---------------- (3) index element of array returned by
       |    |                        function call
       |    +------------------- (2) call function retrieved from name
       |                             binding
       +------------------------ (1) retrieve value bound to variable


It is also worth thinking about what is meant by saying that this
evaluation is *dynamic*.  For example, if the object returned by
the function call to getArray (above) is not indexable, then the []
operator will fail.

And, the only limiting factor is confusion.

Dave

-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman
dkuhlman at rexx.com




More information about the Python-list mailing list