Size of tuples

Brian Quinlan BrianQ at ActiveState.com
Wed Sep 5 21:25:02 CEST 2001


> Does anyone anyone know what the maximum size of
> a tuple can be? Examples in documentation only contains
> a small amount of data, but I like to know if they can contain
> e.g. >100000 integers. Furthermore I would like to know
> the consequences for performance. Does the 'x in tuple'
> statement perform much worse with the amounts of data
> I have in mind?

A tuple can be as big as the address space that you have available.
Using a list to store a large number of integers would probably be
more convenient though since it doesn't require making a new object
for each append. Anyway:

>>> import time
>>> a = (1,) * 100000 + (9,)
>>> start = time.time(); 9 in a; print time.time() - start
1
0.0200001001358
>>>

So it took 2/100ths of a second to search the entire 100,001 element
tuple.

Cheers,
Brian





More information about the Python-list mailing list