Addressing the last element of a list
__peter__ at web.de
Tue Nov 8 11:21:01 CET 2005
pinkfloydhomer at gmail.com wrote:
> I just want an alias. Ideally, I don't want to deal with pointers or
> special reference "types" etc. After all, this is not C++ :)
> I just want to be able to make a reference to any old thing in Python.
> A list, an integer variable, a function etc. so that I, in complicated
> cases, can make a shorthand. If "myRef" could somehow "point at"
> something long an complicated like a["pos"][-4], that might be
You can do
shorthand = a["pos"]
shorthand = 42 # if a["pos"] is mutable
But the last indirection must always be given explicitly.
More information about the Python-list