Re: Python change a value of a variable by itself.

2009-02-17 Thread Tim Chase
I have the following simple code: r = {} r[1] = [0.00] r_new = {} print r[1][0] r_new[1] = r[1] r_new[1][0] = r[1][0] + 0.02 print r[1][0] It outputs: 0.0 0.02 it is something strange to me since in the first and second case I output the same variable (r[1][0]) and it the two cases it has

Re: Python change a value of a variable by itself.

2009-02-17 Thread Stephen Hansen
On Tue, Feb 17, 2009 at 8:19 AM, Kurda Yon wrote: > r_new[1] = r[1] This is the problem. "r" is a dictionary, a set of key/object pairs in essence. You're making the object that "r[1]" is pointing to a list, a mutable sequence of items. The expression "r[1]" will then return that list object and

Python change a value of a variable by itself.

2009-02-17 Thread Kurda Yon
Hi, I have the following simple code: r = {} r[1] = [0.00] r_new = {} print r[1][0] r_new[1] = r[1] r_new[1][0] = r[1][0] + 0.02 print r[1][0] It outputs: 0.0 0.02 it is something strange to me since in the first and second case I output the same variable (r[1][0]) and it the two cases it ha