[Tutor] Re: When was interned strings dropped (and why)?

hcohen2 hcohen2 at comcast.net
Fri Jan 30 18:55:27 EST 2004


Isr Gish wrote:

>I find that only int's and string's have the same id when they are identical.
>But list's, tuple's and dictionary's have different id's even if theybare identical.
>
>P.s I'm using Python 2.3.2
>
>
>-----Original Message-----
>   >From: "Abel Daniel"<abli at freemail.hu>
>   >Sent: 1/30/04 7:56:01 AM
>   >To: "Daniel Ehrenberg"<littledanehren at yahoo.com>
>   >Cc: "pytutor"<tutor at python.org>
>   >Subject: [Tutor] Re: When was interned strings dropped (and why)?
>     >Daniel Ehrenberg writes:
>   >
>   >> Switch to 2.3. That's what I'm using and I don't have
>   >> that bug. Even identical tuples have the same id.
>   >
>   >Are you sure?
>   >
>   >Python 2.3.3 (#2, Dec 19 2003, 11:28:07) 
>   >[GCC 3.3.3 20031203 (prerelease) (Debian)] on linux2
>   >Type "help", "copyright", "credits" or "license" for more information.
>   >>>> t=(1,2)
>   >>>> tt=(1,2)
>   >>>> t is tt
>   >False
>   >>>> t == tt
>   >True
>   >>>> id(t)
>   >1075955500
>   >>>> id(tt)
>   >1075798540
>   >>>> ttt=t
>   >>>> id(ttt)
>   >1075955500
>   >>>> 
>   >
>   >Of course, if you define 'identical' as 'having the same id' then 'identical
>   >tuples have the same id', but you won't really be able to use this fact.
>   >
>   >-- 
>   >Abel Daniel
>   >
>   
>Good luck
>Isr
>
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>  
>
Isr,

You say it, but on an earlier (buggier?) version it is not quite so clear.

 >>> sL = [12, 'abc', 'ghj']
 >>> aL = sL
 >>> id(sL)
134923940
 >>> id(aL)
134923940
 >>> id([12, 'abc', 'ghj'])
134939756
 >>> aL == sL
1
 >>> aL == [12, 'abc', 'ghj']
1

The lists 'aL' and 'sL' are stored in the exactly the same location,  
There actual value: [12, 'abc', 'ghj'] is found elsewhere.  However, 
both aL and sL are the same as the former though it resides elsewhere.

Try that and see what you get.

Herschel






More information about the Tutor mailing list