Jim Red wrote:[color=blue]
> what is the best way to multiply a tuple or list by a given value
>
> exp.
> multiply (4, 5) by 2 => (8, 10)
>
> cheers
>
> jr[/color]
i.e.:
[color=blue][color=green][color=darkred]
>>> import operator
>>> [ operator.mul(x, 2) for x in (4,5)][/color][/color][/color]
Diez B. Roggisch wrote:
[color=blue][color=green][color=darkred]
>> >>> import operator
>> >>> [ operator.mul(x, 2) for x in (4,5)][/color][/color]
>
>
> Why not simply * ?
>
> [ x * 2 for x in (4,5)]
>[/color]
oops, of course. I had the map function in mind,
which only accepts a function, but this would come
to something like:
li=(4,5)
map(operator.mu l, li, (2,)*len(li))
and is certainly worse then list comprehension :-)
Comment