On Thu, Jan 7, 2010 at 2:16 PM, Anand Balachandran Pillai <
[email protected]> wrote:
>
>
>
>
> It is a good exercise to find out the limit till Python caches
> integers. My guess is that it is somewhere close to 100, i.e
> 100+.
>
I wrote a small program to find this out. And
on my Python runtime (2.6.2), the answer is 257.
def intCacheLimit():
i,l,m=1,range(500),range(500)
while i<500:
x=l[i]
y=m[i]
if x is not y:
print 'Limit',x
break
i+=1
[an...@localhost python]$ python
Python 2.6.2 (r262:71600, Aug 21 2009, 12:23:57)
[GCC 4.4.1 20090818 (Red Hat 4.4.1-6)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from intlimit import *
Limit 257
So Python caches integers till 256 - a nice square integer.
Cool right ?
Others can try it out in other Python versions - my guess
would be it is the same everywhere.
>
>
>
--
--Anand
_______________________________________________
BangPypers mailing list
[email protected]
http://mail.python.org/mailman/listinfo/bangpypers