[Tutor] Long list error

Alan Gauld alan.gauld at btinternet.com
Mon Mar 9 09:53:32 CET 2009


"William Stephens" <wstephens10 at suddenlink.net> wrote

> I was working on a sieve of eratosthenes and ran into an error I 
> don't understand.
>
> >>> size = 10000000000
> >>> l = [0,1]*(size/2)
> OverflowError: cannot fit 'long' into an index-sized integer
>
> Is there a type or something that I can do to prevent this error?

The problem is not really to do with the type, despite the error.
You are multiplying the list contents by 5 billion. This will
create a list with 10 billion entries. Python cannot handle
lists of that length. BUT, I doubt if your PC can even if Python
could. Does your PC really have around 40G of Memory?

> I on the wrong track for such large primes?

I think so. Your PC does not have infinitely large memory.

You need to find an algorithm that keeps the data within
the limits of your hardware. (Just be glad you don't have
a ZX81 with only 1K of RAM...)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/


>
> Thanks,
> William Stephens
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 




More information about the Tutor mailing list