IniziaInizia gratis

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

Questo esercizio fa parte del corso

Writing Efficient Python Code

Visualizza il corso

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# Create a list of integers (0-50) using list comprehension
nums_list_comp = [num for num in ____(____)]
print(nums_list_comp)
Modifica ed esegui il codice