Re: Mutable objects inside tuples - good or bad?

2014-04-07 Thread Paul Kölle
Am 06.04.2014 09:25, schrieb Gary Herron: On 04/05/2014 11:53 PM, John Ladasky wrote: I find this programming pattern to be useful... but can it cause problems? No. What kind of problems are you considering? It won't break Python. It's perfectly legal code. The tuple c is still immutable,

Re: Mutable objects inside tuples - good or bad?

2014-04-07 Thread Chris Angelico
On Tue, Apr 8, 2014 at 1:26 AM, Paul Kölle pkoe...@gmail.com wrote: It seems a tuple's immutability is debatable, or is this another instance of the small-integer-reuse-implementation-detail-artifact? Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) [GCC 4.4.5] on linux2 Type help,

Re: Mutable objects inside tuples - good or bad?

2014-04-07 Thread Paul Kölle
Am 07.04.2014 17:44, schrieb Chris Angelico: On Tue, Apr 8, 2014 at 1:26 AM, Paul Kölle pkoe...@gmail.com wrote: It seems a tuple's immutability is debatable, or is this another instance of the small-integer-reuse-implementation-detail-artifact? Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48)

Re: Mutable objects inside tuples - good or bad?

2014-04-07 Thread Chris Angelico
On Tue, Apr 8, 2014 at 5:46 AM, Paul Kölle p...@subsignal.org wrote: Thanks Chris, stupid error indeed ;) Error, at least :) This is why we have a mailing list: errors, inaccuracies, and typos, regardless of who makes them or when, are pretty much guaranteed to be caught. ChrisA --

Re: Mutable objects inside tuples - good or bad?

2014-04-07 Thread Terry Reedy
On 4/7/2014 11:26 AM, Paul Kölle wrote: c = (1,2,3) d = (1,2,3) c is d False An implementation would be allowed to make that True, as it does for small ints and short strings that could be identifiers. a = 'one' b = 'one' a == b; a is b True True However, duplicate tuples are

Re: Mutable objects inside tuples - good or bad?

2014-04-07 Thread Steven D'Aprano
On Mon, 07 Apr 2014 20:16:05 -0400, Terry Reedy wrote: On 4/7/2014 11:26 AM, Paul Kölle wrote: c = (1,2,3) d = (1,2,3) c is d False An implementation would be allowed to make that True, as it does for small ints and short strings that could be identifiers. And indeed, that

Mutable objects inside tuples - good or bad?

2014-04-06 Thread John Ladasky
I find this programming pattern to be useful... but can it cause problems? Python 3.3.2+ (default, Feb 28 2014, 00:52:16) [GCC 4.8.1] on linux Type help, copyright, credits or license for more information. a = [1,2,3] b = [4,5,6] c = (a,b) c ([1, 2, 3], [4, 5, 6]) c[0][0] = 0 c ([0, 2, 3],

Re: Mutable objects inside tuples - good or bad?

2014-04-06 Thread Gary Herron
On 04/05/2014 11:53 PM, John Ladasky wrote: I find this programming pattern to be useful... but can it cause problems? No. What kind of problems are you considering? It won't break Python. It's perfectly legal code. The tuple c is still immutable, consisting of two specific objects, and

Re: Mutable objects inside tuples - good or bad?

2014-04-06 Thread Devin Jeanpierre
On Sun, Apr 6, 2014 at 12:25 AM, Gary Herron gary.her...@islandtraining.com wrote: On 04/05/2014 11:53 PM, John Ladasky wrote: I find this programming pattern to be useful... but can it cause problems? No. What kind of problems are you considering? It won't break Python. It's perfectly

Re: Mutable objects inside tuples - good or bad?

2014-04-06 Thread Chris Angelico
On Sun, Apr 6, 2014 at 5:55 PM, Devin Jeanpierre jeanpierr...@gmail.com wrote: On Sun, Apr 6, 2014 at 12:25 AM, Gary Herron gary.her...@islandtraining.com wrote: On 04/05/2014 11:53 PM, John Ladasky wrote: I find this programming pattern to be useful... but can it cause problems? No. What

Re: Mutable objects inside tuples - good or bad?

2014-04-06 Thread Devin Jeanpierre
On Sun, Apr 6, 2014 at 1:25 AM, Chris Angelico ros...@gmail.com wrote: On Sun, Apr 6, 2014 at 5:55 PM, Devin Jeanpierre jeanpierr...@gmail.com wrote: Agreed. Putting mutable objects inside tuples is common and totally OK. There are many programming habits that can cause problems, even though

Re: Mutable objects inside tuples - good or bad?

2014-04-06 Thread Rustom Mody
On Sunday, April 6, 2014 1:40:58 PM UTC+5:45, Devin Jeanpierre wrote: You can choose to define mutability that way, but in many contexts you'll find that definition not very useful. c is such that you could have another variable d, where the following interpreter session fragment is easily