[Tutor] Memroy Error - how to manage large data sets?
kinuthiA muchanE
muchanek at gmail.com
Tue Jul 29 14:37:00 CEST 2008
On Tue, 2008-07-29 at 12:00 +0200, tutor-request at python.org wrote:
> Message: 2
> Date: Tue, 29 Jul 2008 08:44:40 +0100
> From: "Alan Gauld" <alan.gauld at btinternet.com>
> Subject: Re: [Tutor] Tutor Digest, Vol 53, Issue 99
> To: tutor at python.org
> Message-ID: <g6mhlf$8p7$1 at ger.gmane.org>
> Content-Type: text/plain; format=flowed; charset="iso-8859-1";
> reply-type=original
>
> "kinuthiA muchanE" <muchanek at gmail.com> wrote
>
> > I have realised that when you need to work with large numbers,
> lists
> > are
> > slow and tend to gobble up bytes.
>
> The lists are not particularly slow (obviously if you want to
> traverse them they take longer for more members) and they
> don't take up much more memory that the sum of the sizes
> of whats in them.
>
> The problem here is that the data items themselves are huge.
> Around 20K per item. Thus a million times 20K is 20G!
>
> > This is how I would approach the problem, without using
> > lists.
>
> Yep, we all seem to be pretty much in agreement :-)
>
> > It produces the result instantly, even for large numbers like a
> > 100, 000, 000.
>
> Umm, not instantly on my PC... 1 million took 5 minutes,
> I've no idea how long 100 million would take!
I think the question is to calculate the sum of all even numbers in the
Fibonacci series which do not exceed a million, not the millionth term.
Number 25 on Project Euler which asks for first term in the Fibonacci
series to contain 1000 digits, is the term-wise question ;)
>
> > def fibonacci()
> > a = 0
> > b = 1
> > evenTotal = 0
> > while a < 100000000:
> > a,b = b,a+b
> > if a%2 == 0:
> > evenTotal += a
> > print evenTotal
>
> Alan G
>
>
>
>
> ------------------------
More information about the Tutor
mailing list