[Tutor] Memory error - how to manage large data sets?

Karthik rs.karthick at gmail.com
Mon Jul 28 19:14:08 CEST 2008


Forgot to include the following information,

 

Platform - win32

Version - 2.5.1

 

Error message:

 

Traceback (most recent call last):

  File "C:\Python25\programs\fibo.py", line 10, in <module>

    if i % 2 == 0:

MemoryError

 

Code:

 

fib = []

even = []

def fibonacci(x,y):

    return x+y

for i in range (0,1000000):

    if i < 2:

        fib.append(i)

    else:

        i = fib[i-1] + fib[i-2]

        if i % 2 == 0:

            fib.append(i)

            even.append(i)

        else:

            fib.append(i)

total = reduce(fibonacci,even)

print total

 

Any pointers would be of great help to me.

 

Regards,

Karthik

 

From: Karthik [mailto:rs.karthick at gmail.com] 
Sent: Monday, July 28, 2008 9:27 PM
To: 'tutor at python.org'
Subject: Memory error - how to manage large data sets?

 

Hi,

 

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.

 

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.

2.     I have used lists to achieve this.

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.

 

Thanks in advance,

Karthik

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080728/ff9e0107/attachment-0001.htm>


More information about the Tutor mailing list