
On Thu, Feb 11, 2010 at 10:38 AM, Tim Lesher <tlesher@gmail.com> wrote:
On Thu, Feb 11, 2010 at 10:21, Matthew Russell <matt.horizon5@gmail.com> wrote:
this seems to work in python 2.x and python3.1, although I suspect it's a bug.
t = (1, 2) t += (3,) t (1, 2, 3)
The object "t" references at the end isn't the same one that it references at the beginning. Note the difference between lists and tuples here:
a = [1,2] id(a) 11274840 a += [3,] id(a) 11274840 a is a list; augmented assignment mutates it, but it's still the same object. b = (1,2) id(b) 13902872 b += (3,) id(b) 13915800
b is a tuple; augmented assignment creates a new object and re-binds "b" to it. -- Tim Lesher <tlesher@gmail.com>
_______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas
Thanks all for helping me understand this better. The subtly above is something I missed. I searched the doc for a description of it but couldn't readily find it. Tim's simple one-line statement and the example above does it very nicely. Switching gears for a moment, what is the feeling regarding the copy() methods for dictionaries and sets? Are they truly redundant? Should they be deprecated? Should users be encouraged to use the copy module or just use "newdict = dict(olddict)" and "newset = set(oldset)" to build a new dictionary or set from an existing one? -- Gerald Britton