How many is "too many" with lists?

Aahz Maruch aahz at netcom.com
Tue May 2 11:27:18 EDT 2000


In article <meh9-D76210.11174702052000 at news.cit.cornell.edu>,
Matthew Hirsch  <meh9 at cornell.edu> wrote:
>
>Is there a rough number of elements in a list that python or a computer 
>has trouble dealing with?  I'm using a P233 with 64MB RAM.  I have 
>~25000 elements in a list, and things seem to be slowing down.  Is there 
>some number that I should try avoiding?

Depends what you're doing.  Obviously, if the total size of the list
exceeds the available RAM, swapping will make things slow.  OTOH, 25K
elements shouldn't take up that much space unless each element is a long
string or something.  Note that the "in" operator as applied to "if" or
"while" is a *linear* search and will take a long time, generally
speaking; this is usually the primary suspect for people complaining
about slow list speed.
--
                      --- Aahz (Copyright 2000 by aahz at netcom.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

"Laws that restrict speech are an abomination for a simple reason.
They're like a poison gas; they seem to be a good weapon to vanquish
your enemy, but the wind has a way of shifting."  -- Ira Glasser



More information about the Python-list mailing list