For loop searching takes too long!

Steven D'Aprano steve at
Sat Jan 30 04:07:52 CET 2010

On Fri, 29 Jan 2010 14:49:06 -0800, Jonathan Gardner wrote:

> On Jan 28, 3:52 pm, elsa <kerensael... at> wrote:
>> I've got a problem with my program, in that the code just takes too
>> long to run. Here's what I'm doing. If anyone has any tips, they'd be
>> much appreciated!
> First of all, don't play with large lists. Large lists have a tendency
> to grow larger over time, until they get absurdly large.
> If you're dealing with a long list, work with it like you'd work with a
> file. If you need random access, stick it in some form of database, such
> as BDB or PostgreSQL. If you need an index, stick it in some form of DB.
> Eventually, large lists end up like that anyway. Don't fool yourself
> early on---prepare for the worst and solve the problems of tomorrow
> today.

Talk about premature optimization. The OP probably has a few hundreds of 
thousands of items, millions at most, which is trivial on a modern PC. 
Your way of thinking is what has led to Firefox using a database to 
manage a few thousand bookmarks and cookies, which in turn leads to 
consistent data corruption problems. (I've been keeping note, and so far 
my installation of Firefox 3 has had database corruption at startup one 
time out of five.)


More information about the Python-list mailing list