Steven D'Aprano wrote: > jc wrote: >> n = 900 >> cache = range(0 , n + 1 , 1) >> for i in cache: >> cache[i] = -1 > > This is a waste of time. Better to write: > > cache = [-1]*900
Since he's computing the Fibonacci number of n, and n is 900, he needs cache = [-1] * (n + 1) ;^) > Even better is to use a dict instead of a list. Simpler, yes. Better for a beginner, of course. Better, maybe not. The use case here will cause the cache to be used from index 1 upwards, so using an array to store the element is faster and smaller. I'd consider resizing the cache dynamically though. Cheers! Uli -- Domino Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 -- http://mail.python.org/mailman/listinfo/python-list