August 2018
Intermediate to advanced
366 pages
10h 14m
English
We can easily adapt operator.mul to be a unary function and then pass it to map to apply it to the whole list:
>>> import functools, operator >>> >>> values = range(10) >>> mul3 = functools.partial(operator.mul, 3) >>> list(map(mul3, values)) [0, 3, 6, 9, 12, 15, 18, 21, 24, 27]
As you can see, operator.mul was called with 3 and the item as its arguments, and thus returned item*3.