May 2019
Beginner
528 pages
29h 51m
English
array Performance: Introducing %timeitMost array operations execute significantly faster than corresponding list operations. To demonstrate, we’ll use the IPython %timeit magic command, which times the average duration of operations. Note that the times displayed on your system may vary from what we show here.
We’ve demonstrated rolling a six-sided die 6,000,000 times. Here, let’s use the random module’s randrange function with a list comprehension to create a list of six million die rolls and time the operation using %timeit. Note that we used the line-continuation character (\) to split the statement in snippet [2] over two lines:
In [1]: import random ...Read now
Unlock full access