Oct-02-2016, 08:56 AM
The performance difference is small,if want to know just use timeit.
Here are all 3 and also tested with PyPy.:cool:
Here are all 3 and also tested with PyPy.:cool:
import timeit ordinary_loop = '''\ lst = ['1', '500', '999'] l = [] for i in lst: l.append(int(i)) ''' # 21.14 sec # PyPy 3 sec list_comp = '''\ lst = ['1', '500', '999'] [int(i) for i in lst] ''' # 20.54 sec # PyPy 2.59 sec _map = '''\ lst = ['1', '500', '999'] list(map(int, lst)) ''' # 22.6 sec # PyPy 3.5 sec print(timeit.Timer(stmt=_map).timeit(number=10000000))