[Tutor] Memory error - how to manage large data sets?
Alan Gauld
alan.gauld at btinternet.com
Mon Jul 28 18:46:27 CEST 2008
"Karthik" <rs.karthick at gmail.com> wrote
> I am new to Python programming, I was trying to work out a few
> problems in
> order to grasp the knowledge gained after going through the basic
> chapters
> on Python programming. I got stuck with a memory error.
Always show us the full error text, it contains a lot of useful data.
It is usually helpful to show us the code too if not too long.
Alternatively post in on a web site such as pastebin.
> Following is what I did,
> 1. I need to find the sum of all numbers at even positions in
> the
> Fibonacci series upto 2 million.
Shouldn't be a problem.
> 2. I have used lists to achieve this.
One list should suffice. (and you could do it without any lists...)
> 3. My program works good with smaller ranges. Say till 10,000 or
> even
> 100,000. However when I compute the sum for bigger ranges it gives
> me the
> memory error.
>
> 4. Also could someone tell me how to get the result in the form
> of an
> exponent. For instance, I would prefer 10^5 rather 100000.
You can use string formatting using the %e or %g markers.
See my tutorial topic Simple Sequences for more info on format strings
or search the documentation.
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list