Declare list of large size
Neal Norwitz
neal at metaslash.com
Mon Mar 18 18:08:16 EST 2002
Aaron Ginn wrote:
>
> Perhaps I've just glossed over this in the documentation, but what is
> the simplest way to declare a list of large size? Is there something
> analogous to the following in C:
>
> int list[100];
>
> I can do this by doing the following:
>
> list = []
> i=0
> while i < 100:
> list.append[0]
> i = i + 1
>
> which will give me a list 100 elements long with all values
> initialized to 0, but I'm assuming there has to be an easier way to do
> this? Am I correct in this assumption?
Yes:
>>> [0]* 100
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>>>
Neal
More information about the Python-list
mailing list