[Tutor] List initialisation

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Fri, 26 Jul 2002 02:39:01 -0700 (PDT)


On Fri, 26 Jul 2002, Guillermo Fernandez wrote:

> I've been trying to initialise a list containing a number 'size' of
> zeros. After looking in the doc and tutorials, I've done it like this:
>
> def zero(x): return 0
> list=map(zero, range(0,size))

Hi Guillermo,

Here's an alterative way of making a presized list:

    mylist = [0] * size


By the way, be careful about using the name 'list' as a variable name ---
there's a very useful builtin function named 'list()' already, and it's
not usually a good idea to mask it.  Other ones to try avoid are things
like 'int', 'float', and 'range'.


If you have more questions, please feel free to ask.  Good luck!