multiply utple or list

P at draigBrady.com P at draigBrady.com
Thu Feb 19 09:50:13 EST 2004


Jim Red wrote:
> what is the best way to multiply a tuple or list by a given value
> 
> exp.
> multiply (4, 5) by 2 => (8, 10)

something like this?

import types
def multiply_sequence(sequence, multiplier):
     new_sequence = map(lambda item: item*multiplier, sequence)
     if type(sequence) == types.TupleType:
         return tuple(new_sequence)
     elif type(sequence) == types.ListType:
         return new_sequence

-- 
Pádraig Brady - http://www.pixelbeat.org




More information about the Python-list mailing list