multiply utple or list

Karl Scalet news at yebu.de
Thu Feb 19 16:58:02 CET 2004


Diez B. Roggisch wrote:

>> >>> import operator
>> >>> [ operator.mul(x,2) for x in (4,5)]
> 
> 
> Why not simply * ?
> 
> [ x * 2 for x in (4,5)]
> 

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.mul, li, (2,)*len(li))

and is certainly worse then list comprehension :-)

regards,
Karl




More information about the Python-list mailing list