How to use a 5 or 6 bit integer in Python?

Gabriel Genellina gagenellina at softlab.com.ar
Fri Dec 19 01:17:28 EST 2003


At 19/12/2003 14:30, you wrote:

>   I have one constantly changing dict with many millions of keys
>(tuples of ints) which in turn associates itself with a tuple of ints
>and two more dicts.

How big are the integers? If 16 bits for each are enough, you could replace 
those 2-elem tuples with an plain integer: (a,b) -> a<<16 | b
You dont waste space from a tuple object (and its construction time) plus 
two references for each dictionary key used, but you eventually create many 
more integer instances. And there is a penalty accessing the dictionary 
since you have to compute the key.


Gabriel Genellina
Softlab SRL






More information about the Python-list mailing list