J
Jim Red
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
exp.
multiply (4, 5) by 2 => (8, 10)
cheers
jr
Jim said: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
i.e.:
>>> import operator
>>> [ operator.mul(x,2) for x in (4,5)]
Jim said:what is the best way to multiply a tuple or list by a given value
exp.
multiply (4, 5) by 2 => (8, 10)
[ operator.mul(x,2) for x in (4,5)]
Diez said:import operator
[ operator.mul(x,2) for x in (4,5)]
Why not simply * ?
[ x * 2 for x in (4,5)]
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.