-1

In Python, is there a shorter way to implement this:

x = [func(i) for i in x] , 

for given function func and list x ?

ivand58
  • 773
  • 6
  • 19

1 Answers1

2

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))
Anand S Kumar
  • 88,551
  • 18
  • 188
  • 176