How can I implement this ipython code in python?
[1] %timeit sum(list(range(1000)))
Ps: I want to do it in a single line of code. I have tried several times but failed every time.
Thanks.
How can I implement this ipython code in python?
[1] %timeit sum(list(range(1000)))
Ps: I want to do it in a single line of code. I have tried several times but failed every time.
Thanks.
This will give you the time taken (in seconds):
from timeit import timeit
timeTaken = timeit(lambda: sum(list(range(1000))), number=100000)
You can look up the timeit documentation for more options.