multiply utple or list

Diez B. Roggisch nospam-deets at web.de
Thu Feb 19 16:19:35 CET 2004


>  >>> import operator
>  >>> [ operator.mul(x,2) for x in (4,5)]

Why not simply * ?

[ x * 2 for x in (4,5)]

And you might surround it by tuple to gain a tuple

tuple([ x * 2 for x in (4,5)])

Another way would be to use Numeric

import Numeric
a = Numeric.array((10,2), Numeric.Float32)
a = a * 2


-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list