Addressing the last element of a list
Antoon Pardon
apardon at forel.vub.ac.be
Mon Nov 14 06:20:53 EST 2005
Op 2005-11-14, Paul Rubin schreef <http>:
> Antoon Pardon <apardon at forel.vub.ac.be> writes:
>> We could then have something like the following.
>>
>> a = 5
>> b = a
>> a @= 7
>> b ==> would result in 7.
>
> Ouch! :-(((
>
> Can't you live with
>
> a = [5]
> b = a
> a[0] = 7
>
> so b[0] is now 7.
And what do I have to do, in case of the following:
a = [3, 5]
b = a[0]
b @= 7
a ==> would result in [7, 5]
This may seem contrived, but in combination with
parameters it could be usefull.
Something like:
a = [3, 5]
def treat(b):
lots of code
b @= new_value
f(a[0])
a ==> would result in [7, 5]
--
Antoon Pardon
More information about the Python-list
mailing list