Two candies
Raymond Hettinger
python at rcn.com
Wed Jan 2 11:44:49 EST 2008
[bearophileH]
>
> 1) A fast and memory efficient way to create an array.array at a
> certain size.
> At the moment I can see some ways to do it:
>
> from array import array
> from itertools import repeat
> a = array("l", repeat(0, n)) #3
. . .
> - #3 interacts badly with Psyco (Psyco doesn't digest itertools at
> all), and it seems not memory efficient.
#3 is a fine choice. It is memory efficient -- the repeat() itertool
takes-up only a few bytes. It doesn't need psyco, you already have to
fast C routines talking to each other without having to go through the
interpreter loop.
Raymond
More information about the Python-list
mailing list