Why these don't work??

Lie Ryan lie.1296 at gmail.com
Fri Apr 9 02:35:41 CEST 2010

On 04/09/10 06:36, Robert Kern wrote:
> On 2010-04-08 15:08 PM, M. Hamed wrote:
>> On the other hand (other than installing NumPy) is there a built-in
>> way to do an array full of zeros or one just like the numpy.zeros()? I
>> know I can do it with list comprehension (like [0 for i in
>> range(0,20)] but these are too many keystrokes for python :) I was
>> wondering if there is a simpler way.
> [0] * n

Be careful there, that idiom only works (or only work reasonably) when
`0` is immutable (since integer is immutable, the idiom happens to work

More information about the Python-list mailing list