On Feb 18, 2008 9:07 PM, David Brown <[EMAIL PROTECTED]> wrote:
> Another way to think of it.  A python list is an arbitrary-length tuple.
> An element of that tuple could refer to the tuple itself, but the
> individual pieces can't be referred to.

I get it now, thanks.

There is a ghastly trick in Python for making an element in a list
addressable: You wrap every element of the list in a list regardless
of what that element is. Now when you say t[i] you get back the list
holding the element you are really interested in. This is like a
reference in that you can change what's referred to in the original
structure:

>>> t = [[1], [2]]
>>> element = t[0]
>>> print element[0]  # deref the element for its value
1
>>> element[0] = 4  # alter the element via its "reference"
>>> t  # show that the element referred to has been changed
[[4], [2]]
>>>

Mwahahaha!

-- 
http://cobra-language.com/

-- 
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to