Declare list of large size

Kendall Clark kendall at monkeyfist.com
Mon Mar 18 18:13:26 EST 2002


On Mon, Mar 18, 2002 at 03:44:14PM -0700, Aaron Ginn wrote:

> 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?

>> l = [0 for i in range(100)]

>> print l

<list of 100 elements, each of which is 0 snipped>

>> len(l)
100

List comprehensions are everyone's friend.

Best,
Kendall




More information about the Python-list mailing list