In Python, is there a shorter way to implement this:
x = [func(i) for i in x] ,
for given function func and list x ?
In Python, is there a shorter way to implement this:
x = [func(i) for i in x] ,
for given function func and list x ?
You can use the map
function, its shorter to write, but it a little more time consuming from my experience.
Example -
x = map(func, x)
For Python 3.x , map
returns an iterator, so you need to explicitly convert it to list
-
x = list(map(func, x))