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

Danny Yoo dyoo at cs.wpi.edu
Mon Jul 28 20:23:36 CEST 2008


> 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.

I see.  You may want to produce a "sequence" or "iterator" of
fibonacci numbers rather than an explicit list.  As it is, your
machine does not have enough physical memory to hold the whole
sequence at once.

Python has a "generator" language feature that supports a style of
programming on infinite sequences.  You can find an introduction to
Python generators here:

    http://linuxgazette.net/100/pramode.html


More information about the Tutor mailing list