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 |
Deze oefening maakt deel uit van de cursus
Writing Efficient Python Code
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Create a list of integers (0-50) using list comprehension
nums_list_comp = [num for num in ____(____)]
print(nums_list_comp)