Using %timeit: your turn!
You'd like to create a list of integers from 0 to 50 using the range()
function. However, you are unsure whether using list comprehension or unpacking the range object into a list is faster. Let's use %timeit
to find the best implementation.
For your convenience, a reference table of time orders of magnitude is provided below (faster at the top).
symbol | name | unit (s) |
---|---|---|
ns | nanosecond | 10-9 |
µs (us) | microsecond | 10-6 |
ms | millisecond | 10-3 |
s | second | 100 |
This exercise is part of the course
Writing Efficient Python Code
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create a list of integers (0-50) using list comprehension
nums_list_comp = [num for num in ____(____)]
print(nums_list_comp)