multiply each element of a list by a number

Colin J. Williams cjw at ncf.ca
Sat Dec 27 17:14:27 EST 2008


Méta-MCI (MVP) wrote:
> Hi!
> 
>> map(multby3, (1, 2, 3, ))
> 
> ....with lambda:     map(lambda x: x*3, [1,2,3])
> 
> @-salutations

More lines but perhaps faster than numpy:

PythonWin 2.5.4 (r254:67916, Dec 23 
2008, 15:10:54) [MSC v.1310 32 bit 
(Intel)] on win32.
Portions Copyright 1994-2008 Mark 
Hammond - see 'Help/About PythonWin' for 
further copyright information.
>>> lst= [1,2,3]
>>> trippleList= [3*a for a in lst]
>>> trippleList
[3, 6, 9]
>>> 

Colin W.



More information about the Python-list mailing list