maximum length of a list & tuple
Steve
dippyd at yahoo.com.au
Wed Apr 14 03:38:23 EDT 2004
Lupe wrote:
> I just would like to know if there is any limit to a list or tuple.
Yes. Since the universe only contains something like
10**85 particles of matter, the upper limit to a list
is roughly 2**(10**85) bits.
Sorry, I couldn't resist :-D
You can store as many things in a list as you have
memory for. I suppose there is probably some
fundamental limit due to 32 bit addressing issues, but
are you sure you are really storing so many items you
are hitting that limit? I'd guess you aren't.
For example, the other day I was playing around with
Python, and just for a lark I created a list with
300,000,000 instances of None. It took about five
minutes, but it worked :-)
Going back to your original problem:
> Each time the function is called, it compares an
> element of a list (which is a list too) to other
> elements, which all amounts to millions of
> comparisons.
Are you sure there isn't a more efficient algorithm for
what you are trying to do?
> The program is working for short lists but not for
> longer ones.
What do you mean it is working? It doesn't finish? It
is too slow? Or it gives the wrong answer?
If it is giving a wrong answer, there is a bug in your
code. If it is running too slowly, chances are there is
a better algorithm that will fix it.
--
Steven D'Aprano
More information about the Python-list
mailing list