multiply each element of a list by a number

Benjamin Kaplan benjamin.kaplan at case.edu
Fri Dec 26 19:41:39 EST 2008


On Fri, Dec 26, 2008 at 7:05 PM, <Robert.T.Lynch at seagate.com> wrote:

>
> What does *not* work is
>         3 * [0,1,2]
> As you know, this gives
>         [0,1,2,0,1,2,0,1,2]
> What I am hoping for is
>         [0,3,6]
> I see that I can use
>         numpy.multiply(3,range(3))
> but this seems overkill to me.  Can you tell I am coming to Python from
> Matlab?
>
> Thanks -- Rob


you can do [i * 3 for i in range(3)]



>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081226/41a1a69e/attachment-0001.html>


More information about the Python-list mailing list