How to initialize an array with a large number of members ?

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Wed Dec 31 19:42:42 CET 2008


MRAB:
>  >>> # With a list
>  >>> tally = array('H', [0] * 75)
>  >>>
>  >>> # With a generator
>  >>> tally = array('H', (0 for i in range(75)))

Time ago we have had a long discussion about this, the right way is:

tally = array(someformat, [0]) * 75

(If you need to initialize it to something that isn't constant then
you may have to do something different).

Bye,
bearophile



More information about the Python-list mailing list