Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #69819

Re: Mutable objects inside tuples - good or bad?

From Paul Kölle <paul@subsignal.org>
Subject Re: Mutable objects inside tuples - good or bad?
Date 2014-04-07 21:46 +0200
References <89df32f9-c8ae-4b7b-bfc4-01c574aabcae@googlegroups.com> <53410185.6050304@islandtraining.com> <5342C3AD.9080707@subsignal.org> <CAPTjJmoP_f3BEr3j+PD+KutAhiWPxPXrSUqPgmp7SDTJmJcA5Q@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.8984.1396900024.18130.python-list@python.org> (permalink)

Show all headers | View raw


Am 07.04.2014 17:44, schrieb Chris Angelico:
> On Tue, Apr 8, 2014 at 1:26 AM, Paul Kölle <pkoelle@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", "copyright", "credits" or "license" for more information.
>>>>> a = ([1,2],[3,4])
>>>>> b = a
>>>>> a is b
>> True
>>>>> a == b
>> True
>>>>> c = (1,2,3)
>>>>> d = (1,2,3)
>>>>> c is d
>> False
>>>>> c == d
>> True
>
> That's nothing to do with mutability or reuse. With a and b, you
> assigned one to be the same as the other, so they are by definition
> identical (and equal; tuples assume that identity implies equality,
> even though that may not be true of their elements). With c and d, you
> assigned separate tuples, so they're allowed to be separate objects.
> I'm not sure if they're allowed to be constant-folded, but CPython
> apparently isn't doing so. They are still equal, though; they contain
> equal elements, ergo they are equal. (Note that (1, 2, 3) and (1.0,
> 2.0, 3.0) are equal, but they obviously can't be identical any more
> than "1 is 1.0" can ever be True.)
>
> ChrisA
>
Thanks Chris, stupid error indeed ;)

cheers
  Paul

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Mutable objects inside tuples - good or bad? John Ladasky <john_ladasky@sbcglobal.net> - 2014-04-05 23:53 -0700
  Re: Mutable objects inside tuples - good or bad? Gary Herron <gary.herron@islandtraining.com> - 2014-04-06 00:25 -0700
  Re: Mutable objects inside tuples - good or bad? Devin Jeanpierre <jeanpierreda@gmail.com> - 2014-04-06 00:55 -0700
    Re: Mutable objects inside tuples - good or bad? Rustom Mody <rustompmody@gmail.com> - 2014-04-06 08:07 -0700
  Re: Mutable objects inside tuples - good or bad? Chris Angelico <rosuav@gmail.com> - 2014-04-06 18:25 +1000
  Re: Mutable objects inside tuples - good or bad? Devin Jeanpierre <jeanpierreda@gmail.com> - 2014-04-06 04:01 -0700
  Re: Mutable objects inside tuples - good or bad? Paul Kölle <paul@subsignal.org> - 2014-04-07 17:26 +0200
  Re: Mutable objects inside tuples - good or bad? Chris Angelico <rosuav@gmail.com> - 2014-04-08 01:44 +1000
  Re: Mutable objects inside tuples - good or bad? Paul Kölle <paul@subsignal.org> - 2014-04-07 21:46 +0200
  Re: Mutable objects inside tuples - good or bad? Chris Angelico <rosuav@gmail.com> - 2014-04-08 08:47 +1000
  Re: Mutable objects inside tuples - good or bad? Terry Reedy <tjreedy@udel.edu> - 2014-04-07 20:16 -0400
    Re: Mutable objects inside tuples - good or bad? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-04-08 02:53 +0000

csiph-web